Array.prototype.find = function(searchStr) {
	var returnArray = false;
	for (i = 0; i < this.length; i++) {
		if (typeof (searchStr) == 'function') {
			if (searchStr.test(this[i])) {
				returnArray.push(i);
			}
		} else {
			if (this[i] === searchStr) {
				if (!returnArray) {
					returnArray = []
				}
				returnArray.push(i);
			}
		}
	}
	return returnArray;
}
/* validation */
var noValue = 'You must fill the required field: ';
var badEmail = 'E-mail must be valid at: ';
var color = "#DDCFA8";
String.prototype.classExists = function(tC) {
	var rE = new RegExp("(^| )" + tC + "\W*");
	if (rE.test(this)) {
		return true;
	}
	return false;
}
function validateForm(form) {
	var ms = "";
	var c = 0;
	var input, error;
	var lb = form.getElementsByTagName("label");
	var emailpat = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+$/;
	for (i = 0; i < lb.length; i++) {
		error = false;
		input = document.getElementById(lb[i].htmlFor);
		input.style.backgroundColor = "#ffffff";
		if (lb[i].className.classExists("required") && input.value == "") {
			ms = ms + noValue + lb[i].innerHTML + "\n\n";
			error = true;
		}
		if (lb[i].className.classExists("reqEmail")
				&& !emailpat.test(input.value)) {
			ms = ms + badEmail + lb[i].innerHTML + "\n\n";
			error = true;
		}
		if (error) {
			input.style.backgroundColor = color;
			if (c == 0) {
				input.focus();
			}
			c++;
		}
	}
	if (ms != "") {
		alert(ms);
		return (false);
	} else {
		return (true);
	}
}
/* cookies */
function cookiesAllowed() {
	setCookie('checkCookie', 'test', 1);
	if (getCookie('checkCookie')) {
		deleteCookie('checkCookie');
		return true;
	}
	return false;
}
function setCookie(name, value, expires, options) {
	if (options === undefined) {
		options = {};
	}
	if (expires) {
		var expires_date = new Date();
		expires_date.setDate(expires_date.getDate() + expires)
	}
	document.cookie = name + '=' + escape(value)
			+ ((expires) ? ';expires=' + expires_date.toGMTString() : '')
			+ ((options.path) ? ';path=' + options.path : '')
			+ ((options.domain) ? ';domain=' + options.domain : '')
			+ ((options.secure) ? ';secure' : '');
}
function getCookie(name) {
	var start = document.cookie.indexOf(name + "=");
	var len = start + name.length + 1;
	if ((!start) && (name != document.cookie.substring(0, name.length))) {
		return null;
	}
	if (start == -1) {
		return null;
	}
	var end = document.cookie.indexOf(';', len);
	if (end == -1) {
		end = document.cookie.length;
	}
	return unescape(document.cookie.substring(len, end));
}
function deleteCookie(name, path, domain) {
	if (getCookie(name))
		document.cookie = name + '=' + ((path) ? ';path=' + path : '')
				+ ((domain) ? ';domain=' + domain : '')
				+ ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}

$(document).ready(function() {
	/* loading */
	$("#searchLoadingLayer").fadeOut("slow");
	$("#searchContent").show();

	/* wordsCloudTabs */
	$('#wordsCloud li a').hover( function() {
		if ($(this).attr("class") != 'activeTab') {
			$('#wordsCloud li a').toggleClass("activeTab");
			$('#wordsCloud div span').toggleClass("inactiveData");
		}
	});
	
	
	/*search tabs*/
	$('.mainSearchLinksTabsNew .searchTabs li a').hover( function() {
		$('.mainSearchLinksTabsNew .searchTabs li a').removeClass("activeTab");
		$(this).addClass("activeTab");
		$('#searchDaily').addClass("searchHidden");
		$('#searchLast').addClass("searchHidden");
		$('#searchAll').addClass("searchHidden");
		if($(this).attr("id") == 'activeTab1')
		{
			$('#searchDaily').removeClass("searchHidden");
		}
		if($(this).attr("id") == 'activeTab2')
		{
			$('#searchLast').removeClass("searchHidden");
		}
		if($(this).attr("id") == 'activeTab3')
		{
			$('#searchAll').removeClass("searchHidden");
		}
	});
	
	/* savejob */
	var gtmjSJ = getCookie('gtmjSJ');
	if (gtmjSJ) {
		gtmjSJ = gtmjSJ.split(",");
		$("#savedJobsCounter span").text(gtmjSJ.length);
		$("#savedJobsCounter").show();
		var sl = $('.jobItemSave');
		for (x in sl) {
			if (!sl[x].id) {
				continue;
			}
			if (gtmjSJ.find(sl[x].id.replace(/^\D+/g, ""))) {
				$("#" + sl[x].id).removeClass('jobItemSave').addClass(
						'jobItemSaved').text('Job Saved!');
			}
		}
	}
	$('.jobItemSave').click(
			function() {
				var id = $(this)[0].id.replace(/^\D+/g, "");
				addToSavedJobs(id);
				$(this).removeClass('jobItemSave').addClass(
						'jobItemSaved').text('Job Saved!');
			});
	$(".deleteSavedJob").click( function() {
		deleteSavedJob($(this).attr('title'));
		$("#jt" + $(this).attr('title')).slideUp('slow');
	});
	$(".deletAllSavedJobs").click( function() {
		deleteCookie('gtmjSJ', "/");
		$.get("remoteactions/deleteallsavedjobs");
		$("#savedJobsCounter span").text('0');
		$("#savedJobs").slideUp("slow");
	});
	$("#addJobDescription").keyup(function(e){
		var tac = parseInt($("#addJobCounterChars span").html());
		var tfc = jQuery.trim($(this).val());
		var trc = tac - tfc.length;
		if(trc >= 0){
			$("#addJobCounterChars strong").html(trc);
		}else{
			$(this).val(tfc.slice(0,tac));
			alert('Description must be less than '+tac+' characters long');
		}
	});

	/* registerCompany */
	$("input#user_type").click( function() {
		$("#register_company").toggleClass("hidden");
		$("#register_company label").toggleClass("required");
	});

	/* searchfilter options */
	$("#searchFilterControl").click(function(){
		$("#searchFilterLinks").hide();
		$("#searchFilterMenu li").removeClass('searchFilterActiveTab');;
		$(this).hide();
	});
	$("#searchFilterMenu li").click(function(){
		if($(this).hasClass('searchFilterActiveTab')){
			return false;
		}
		$("#searchFilterLinks").show();
		$("#searchFilterControl").show();
		$("#searchFilterLinks").children().hide();
		$(".filter"+$(this).attr("class")).show();
		$(this).siblings().removeClass('searchFilterActiveTab');
		$(this).addClass("searchFilterActiveTab");
	});
	$("#searchFilter h3").click( function() {
		$(this).toggleClass("filterCollapsed");
		$(this).next().toggleClass("hidden");
	});
	
	
	//clear user last search
	$(".deleteRecentSearchItem").click
	(
		function()
		{
			deleteCookie('lastWords[' + $(this).attr("name") + ']', '', '');
			location.reload(true);
		}
	)	
	//end



	//filter title pop
			//$(".filterTitle a").click( function() {$("#searchwithin input[name='xtitle']").val($(this).attr('name'));$("#searchwithin")[0].submit();});
			//$(".filterTitle strong").click( function() {$("#searchwithin input[name='xtitle']").val('');$("#searchwithin")[0].submit();});
			
			var str_filterTitle = $("#searchwithin input[name='xtitle']").val();
		
			var arr_filterTitle = new Array();
			if(str_filterTitle)
			{
				arr_filterTitle = str_filterTitle.split('______');
				arr_filterTitle.splice(arr_filterTitle.length - 1, 1);
			}
			var cnt_filterTitle = 0;
			for(cnt = 0; cnt < arr_filterTitle.length; cnt++)
			{
				$("input[name='" + arr_filterTitle[cnt] + "']").attr('checked', true);
				cnt_filterTitle++;
			}
			//alert(cnt_filterTitle);
			//$(".filterTitle .TitleRes a").click( function() {$("#searchwithin input[name='xTitle']").val($(this).attr('name'));$("#searchwithin")[0].submit();});
			$(".filterTitle strong").click( function() {$("#searchwithin input[name='xtitle']").val('');$("#searchwithin")[0].submit();});
			$(".filterTitle .titleRes a").click
			( 
				function()
				{
					if($("input[name='" + $(this).attr('name') + "']").attr('checked'))
					{
						$("input[name='" + $(this).attr('name') + "']").attr('checked', false);
						indexToDelete = -1;
						for(cnt = 0; cnt < arr_filterTitle.length; cnt++)
						{
							if(arr_filterTitle[cnt] == $(this).attr('name'))
							{
								indexToDelete = cnt;
							}
						}
						if(indexToDelete > -1)
						{
							arr_filterTitle.splice(indexToDelete, 1);
						}
						cnt_filterTitle--;
					}
					else
					{
						$("input[name='" + $(this).attr('name') + "']").attr('checked', true);
						arr_filterTitle[cnt_filterTitle] = $(this).attr('name');
						cnt_filterTitle++;
					}
					//alert(arr_filterTitle.toSource());
				}
			)
			$(".filterTitle .titleRes input").change
			( 
				function()
				{
					if(!$(this).attr('checked'))
					{
						indexToDelete = -1;
						for(cnt = 0; cnt < arr_filterTitle.length; cnt++)
						{
							if(arr_filterTitle[cnt] == $(this).attr('name'))
							{
								indexToDelete = cnt;
							}
						}
						if(indexToDelete > -1)
						{
							arr_filterTitle.splice(indexToDelete, 1);
						}
						cnt_filterTitle--;
					}
					else
					{
						arr_filterTitle[cnt_filterTitle] = $(this).attr('name');
						cnt_filterTitle++;
					}
					//alert(arr_filterTitle.toSource());
				}
			)
			$("#goFilterTitle1, #goFilterTitle2").click
			(
				function()
				{
					var out = '';
					for(cnt = 0; cnt < arr_filterTitle.length; cnt++)
					{
						out += arr_filterTitle[cnt] + '______';
					}
					if(out != '' && out != '______')
					{
						$("#searchwithin input[name='xtitle']").val(out);
						$("#searchwithin")[0].submit();
					}
					else
					{
						$("#searchwithin input[name='xtitle']").val('');
						$("#searchwithin")[0].submit();
					}
				}
			)
			$("#showTitlePopup").click
			(
				function()
				{
					$("#resultsTitle_popup").dialog();
					$('#resultsTitle_popup').dialog('open');
					$('#resultsTitle_popup').dialog('option', 'width', 300);
					$('#resultsTitle_popup').dialog('option', 'height', 360);
				}
			)
		
	//end
	
	
	
	//filter city pop
			//$(".filterCity a").click( function() {$("#searchwithin input[name='xcity']").val($(this).attr('name'));$("#searchwithin")[0].submit();});
			//$(".filterCity strong").click( function() {$("#searchwithin input[name='xcity']").val('');$("#searchwithin")[0].submit();});
			
			var str_filterCity = $("#searchwithin input[name='xcity']").val();
			var arr_filterCity = new Array();
			if(str_filterCity)
			{
				arr_filterCity = str_filterCity.split('______');
				arr_filterCity.splice(arr_filterCity.length - 1, 1);
			}
			var cnt_filterCity = 0;
			for(cnt = 0; cnt < arr_filterCity.length; cnt++)
			{
				$("input[name='" + arr_filterCity[cnt] + "']").attr('checked', true);
				cnt_filterCity++;
			}
			//alert(cnt_filterCity);
			//$(".filterCity .CityRes a").click( function() {$("#searchwithin input[name='xTitle']").val($(this).attr('name'));$("#searchwithin")[0].submit();});
			$(".filterCity strong").click( function() {$("#searchwithin input[name='xcity']").val('');$("#searchwithin")[0].submit();});
			$(".filterCity .cityRes a").click
			( 
				function()
				{
					if($("input[name='" + $(this).attr('name') + "']").attr('checked'))
					{
						$("input[name='" + $(this).attr('name') + "']").attr('checked', false);
						indexToDelete = -1;
						for(cnt = 0; cnt < arr_filterCity.length; cnt++)
						{
							if(arr_filterCity[cnt] == $(this).attr('name'))
							{
								indexToDelete = cnt;
							}
						}
						if(indexToDelete > -1)
						{
							arr_filterCity.splice(indexToDelete, 1);
						}
						cnt_filterCity--;
					}
					else
					{
						$("input[name='" + $(this).attr('name') + "']").attr('checked', true);
						arr_filterCity[cnt_filterCity] = $(this).attr('name');
						cnt_filterCity++;
					}
					//alert(arr_filterCity.toSource());
				}
			)
			$(".filterCity .cityRes input").change
			( 
				function()
				{
					if(!$(this).attr('checked'))
					{
						indexToDelete = -1;
						for(cnt = 0; cnt < arr_filterCity.length; cnt++)
						{
							if(arr_filterCity[cnt] == $(this).attr('name'))
							{
								indexToDelete = cnt;
							}
						}
						if(indexToDelete > -1)
						{
							arr_filterCity.splice(indexToDelete, 1);
						}
						cnt_filterCity--;
					}
					else
					{
						arr_filterCity[cnt_filterCity] = $(this).attr('name');
						cnt_filterCity++;
					}
					//alert(arr_filterCity.toSource());
				}
			)
			$("#goFilterCity1, #goFilterCity2").click
			(
				function()
				{
					var out = '';
					for(cnt = 0; cnt < arr_filterCity.length; cnt++)
					{
						out += arr_filterCity[cnt] + '______';
					}
					if(out != '' && out != '______')
					{
						$("#searchwithin input[name='xcity']").val(out);
						$("#searchwithin")[0].submit();
					}
					else
					{
						$("#searchwithin input[name='xcity']").val('');
						$("#searchwithin")[0].submit();
					}
				}
			)
			$("#showCityPopup").click
			(
				function()
				{
					$("#resultsCity_popup").dialog();
					$('#resultsCity_popup').dialog('open');
					$('#resultsCity_popup').dialog('option', 'width', 300);
					$('#resultsCity_popup').dialog('option', 'height', 360);
				}
			)

			
			
	//end
	
	
	
	
	
	//filter company pop
			//$(".filterCompany a").click( function() {$("#searchwithin input[name='xcompany']").val($(this).attr('name'));$("#searchwithin")[0].submit();});
			//$(".filterCompany strong").click( function() {$("#searchwithin input[name='xcompany']").val('');$("#searchwithin")[0].submit();});
			
			var str_filterCompany = $("#searchwithin input[name='xcompany']").val();
			var arr_filterCompany = new Array();
			if(str_filterCompany)
			{
				arr_filterCompany = str_filterCompany.split('______');
				arr_filterCompany.splice(arr_filterCompany.length - 1, 1);
			}
			var cnt_filterCompany = 0;
			for(cnt = 0; cnt < arr_filterCompany.length; cnt++)
			{
				$("input[name='" + arr_filterCompany[cnt] + "']").attr('checked', true);
				cnt_filterCompany++;
			}
			//alert(cnt_filterCompany);
			//$(".filterCompany .cmpanyRes a").click( function() {$("#searchwithin input[name='xTitle']").val($(this).attr('name'));$("#searchwithin")[0].submit();});
			$(".filterCompany strong").click( function() {$("#searchwithin input[name='xcompany']").val('');$("#searchwithin")[0].submit();});
			$(".filterCompany .companyRes a").click
			( 
				function()
				{
					if($("input[name='" + $(this).attr('name') + "']").attr('checked'))
					{
						$("input[name='" + $(this).attr('name') + "']").attr('checked', false);
						indexToDelete = -1;
						for(cnt = 0; cnt < arr_filterCompany.length; cnt++)
						{
							if(arr_filterCompany[cnt] == $(this).attr('name'))
							{
								indexToDelete = cnt;
							}
						}
						if(indexToDelete > -1)
						{
							arr_filterCompany.splice(indexToDelete, 1);
						}
						cnt_filterCompany--;
					}
					else
					{
						$("input[name='" + $(this).attr('name') + "']").attr('checked', true);
						arr_filterCompany[cnt_filterCompany] = $(this).attr('name');
						cnt_filterCompany++;
					}
					//alert(arr_filterCompany.toSource());
				}
			)
			$(".filterCompany .companyRes input").change
			( 
				function()
				{
					if(!$(this).attr('checked'))
					{
						indexToDelete = -1;
						for(cnt = 0; cnt < arr_filterCompany.length; cnt++)
						{
							if(arr_filterCompany[cnt] == $(this).attr('name'))
							{
								indexToDelete = cnt;
							}
						}
						if(indexToDelete > -1)
						{
							arr_filterCompany.splice(indexToDelete, 1);
						}
						cnt_filterCompany--;
					}
					else
					{
						arr_filterCompany[cnt_filterCompany] = $(this).attr('name');
						cnt_filterCompany++;
					}
					//alert(arr_filterCompany.toSource());
				}
			)
			$("#goFilterCompany1, #goFilterCompany2").click
			(
				function()
				{
					var out = '';
					for(cnt = 0; cnt < arr_filterCompany.length; cnt++)
					{
						out += arr_filterCompany[cnt] + '______';
					}
					if(out != '' && out != '______')
					{
						$("#searchwithin input[name='xcompany']").val(out);
						$("#searchwithin")[0].submit();
					}
					else
					{
						$("#searchwithin input[name='xcompany']").val('');
						$("#searchwithin")[0].submit();
					}
				}
			)
			$("#showCompanyPopup").click
			(
				function()
				{
					$("#resultsCompany_popup").dialog();
					$('#resultsCompany_popup').dialog('open');
					$('#resultsCompany_popup').dialog('option', 'width', 300);
					$('#resultsCompany_popup').dialog('option', 'height', 360);
				}
			)

			
	//end
	
	//filter source pop
			var str_filterSource = $("#searchwithin input[name='xsource']").val();
			var arr_filterSource = new Array();
			if(str_filterSource)
			{
				arr_filterSource = str_filterSource.split('______');
				arr_filterSource.splice(arr_filterSource.length - 1, 1);
			}
			var cnt_filterSource = 0;
			for(cnt = 0; cnt < arr_filterSource.length; cnt++)
			{
				$("input[name='" + arr_filterSource[cnt] + "']").attr('checked', true);
				cnt_filterSource++;
			}
			//alert(cnt_filterSource);
			//$(".filterSource .sourceRes a").click( function() {$("#searchwithin input[name='xsource']").val($(this).attr('name'));$("#searchwithin")[0].submit();});
			$(".filterSource strong").click( function() {$("#searchwithin input[name='xsource']").val('');$("#searchwithin")[0].submit();});
			$(".filterSource .sourceRes a").click
			( 
				function()
				{
					if($("input[name='" + $(this).attr('name') + "']").attr('checked'))
					{
						$("input[name='" + $(this).attr('name') + "']").attr('checked', false);
						indexToDelete = -1;
						for(cnt = 0; cnt < arr_filterSource.length; cnt++)
						{
							if(arr_filterSource[cnt] == $(this).attr('name'))
							{
								indexToDelete = cnt;
							}
						}
						if(indexToDelete > -1)
						{
							arr_filterSource.splice(indexToDelete, 1);
						}
						cnt_filterSource--;
					}
					else
					{
						$("input[name='" + $(this).attr('name') + "']").attr('checked', true);
						arr_filterSource[cnt_filterSource] = $(this).attr('name');
						cnt_filterSource++;
					}
					//alert(arr_filterSource.toSource());
				}
			)
			$(".filterSource .sourceRes input").change
			( 
				function()
				{
					if(!$(this).attr('checked'))
					{
						indexToDelete = -1;
						for(cnt = 0; cnt < arr_filterSource.length; cnt++)
						{
							if(arr_filterSource[cnt] == $(this).attr('name'))
							{
								indexToDelete = cnt;
							}
						}
						if(indexToDelete > -1)
						{
							arr_filterSource.splice(indexToDelete, 1);
						}
						cnt_filterSource--;
					}
					else
					{
						arr_filterSource[cnt_filterSource] = $(this).attr('name');
						cnt_filterSource++;
					}
					//alert(arr_filterSource.toSource());
				}
			)
			$("#goFilterSource1, #goFilterSource2").click
			(
				function()
				{
					var out = '';
					for(cnt = 0; cnt < arr_filterSource.length; cnt++)
					{
						out += arr_filterSource[cnt] + '______';
					}
					if(out != '' && out != '______')
					{
						$("#searchwithin input[name='xsource']").val(out);
						$("#searchwithin")[0].submit();
					}
					else
					{
						$("#searchwithin input[name='xsource']").val('');
						$("#searchwithin")[0].submit();
					}
				}
			)
			$("#showSourcePopup").click
			(
				function()
				{
					$("#resultsSource_popup").dialog();
					$('#resultsSource_popup').dialog('open');
					$('#resultsSource_popup').dialog('option', 'width', 300);
					$('#resultsSource_popup').dialog('option', 'height', 360);
				}
			)
	
	//end
	
	$(".filterDate a").click( function() {$("#searchwithin input[name='xdate']").val($(this).attr('name'));$("#searchwithin")[0].submit();});
	$(".filterDate strong").click( function() {$("#searchwithin input[name='xdate']").val('');$("#searchwithin")[0].submit();});
	$(".filterTimetype a").click( function() {$("#searchwithin input[name='xtimetype']").val($(this).attr('name'));$("#searchwithin")[0].submit();});
	$(".filterTimetype strong").click( function() {$("#searchwithin input[name='xtimetype']").val('');$("#searchwithin")[0].submit();});
	$(".filterZipcode a").click( function() {$("#searchwithin input[name='xzipcode']").val($(this).attr('name'));$("#searchwithin")[0].submit();});
	$(".filterZipcode strong").click( function() {$("#searchwithin input[name='xzipcode']").val('');$("#searchwithin")[0].submit();});

	
	//linked in pop
	var clearTime = 0;
	$(".linkedLogo").click
	(
		function(e)
		{
			$("#linkedInPopup").removeClass("hidden");
			$("#linkedInPopup").css({'position' : 'absolute', 'top' : e.pageY - $("#linkedInPopup").height() - 20, 'left' : e.pageX - ($("#linkedInPopup").width() / 2)});
			clearInterval(clearTime);
			clearTime = setInterval(function(){clearInterval(clearTime); $("#linkedInPopup").addClass("hidden");}, 4000);
		}
	)
	//end
	
	
	
	$(".searchRelatedJobsLink").click( function() {
//		$(".searchRelatedJobs").hide();
		$(this).toggleClass('sfcClose');
		$(this).siblings(".searchRelatedJobs").toggle();
	});

	/* sponsoredlinkslogo */
	$(".sponsorBlock").mouseenter( function() {
		$(".sponsorBlock a img").hide();
		$(this).children('a').children('img').show();
	});
	$("#searchRightPanel").mouseleave( function() {
		self.setTimeout("$('.sponsorBlock a img').hide()",3000);
	});
	// SponsoredJobs details
	$(".sponsoredJob a").bind("click",function(){
		var pcn = $(this).parents().map(function(){return this.className;}).get().join(",");
		if (/(searchRelatedJobs|searchResultItemTools)/.test(pcn) && this.className!='') {
			return true;
		}
		var bid = $(this).parents().map(function(){if(! /sponsoredJob/.test(this.className)){return;}return this.id;}).get();
		$('#sponsoredJobsInfo').html($('#'+bid+' .sponsoredJobDetails').html());
		$('#sponsoredJobsInfo').dialog();
		$('#sponsoredJobsInfo').dialog('open');
		$('#sponsoredJobsInfo').dialog('option', 'autoOpen', false);
		$('#sponsoredJobsInfo').dialog('option', 'modal', true);
		$('#sponsoredJobsInfo').dialog('option', 'width', 480);
		return false;
	});
	
	/*Recomend a job*/
	$(".searchItemSend,.jobItemSend").bind('click',function(){
		$('#sendJobsForm').dialog();
		$('#sendJobsForm').dialog('open');
		$('#sendJobsForm').dialog('option', 'autoOpen', false);
		$('#sendJobsForm').dialog('option', 'modal', true);
		$('#sendJobsForm').dialog('option', 'width', 480);
		$('#sendForm').attr('action',$(this).attr('href'));
		return false;
	});
	$("#sendJobsForm #sendForm").bind('submit',function(){
		if(!validateForm(document.getElementById('sendForm'))){
			return false;
		}
		$.post($(this).attr('action'), $(this).serialize(),
		function(data){
			if(/e-mail naar uw collega is verstuurd/i.test(data)){
				alert('E-mail naar uw collega is verstuurd');
				$('#sendJobsForm').dialog('close');
			}else{
				alert('There are a problem with the send');
			}
		});
		return false;
	});

	/* gallery */
	$('.gallery_demo_unstyled').addClass('gallery_demo');
	$('ul.gallery_demo').galleria( {
		history :false,
		clickNext :true,
		insert :'#main_image',
		onImage : function(image, caption, thumb) {
			image.css('display', 'none').fadeIn(1000);
			caption.css('display', 'none').fadeIn(1000);
			var _li = thumb.parents('li');
			_li.siblings().children('img.selected').fadeTo(500, 0.3);
			thumb.fadeTo('fast', 1).addClass('selected');
			image.attr('title', 'Next image >>');
		},
		onThumb : function(thumb) {
			var _li = thumb.parents('li');
			var _fadeTo = _li.is('.active') ? '1' : '0.3';
			thumb.css( {
				display :'none',
				opacity :_fadeTo
			}).fadeIn(1500);
			thumb.hover( function() {
				thumb.fadeTo('fast', 1);
			}, function() {
				_li.not('.active').children('img').fadeTo('fast', 0.3);
			})
		}
	});
});

/**
 * Add an item to saved jobs
 * @param int id
 * @return bool
 */
function addToSavedJobs(id) {
	if (!id) {
		return false;
	}
	var gtmjSJ = getCookie('gtmjSJ');
	if (gtmjSJ) {
		gtmjSJ = gtmjSJ.split(",");
		if (gtmjSJ.find(id)) {
			return false;
		}
	} else {
		gtmjSJ = new Array();
	}
	gtmjSJ.push(id);
	$("#savedJobsCounter").show();
	$("#savedJobsCounter span").text(gtmjSJ.length);
	setCookie('gtmjSJ', gtmjSJ.toString(), 30, {
		path :"/"
	});
	
	$("#iframeActions iframe").attr('src', "http://62.129.149.16/remoteactions/addtosavedjob/"+id);
	/*
	$.get("remoteactions/addtosavedjob/"+id, 
	function(data){
	  alert("Data Loaded: " + data);
	}
	); */ //remoteactions/addtosavedjob/4725404     http://gotomyjob.com/jobclick/4725404/Otwee_B_V_zoekt_Assistent-Accountant
	return true;
}
/**
 * Delete an item from saved jobs
 * @param int id
 * @return bool
 */
function deleteSavedJob(id) {
	if (!id) {
		return false;
	}
	var gtmjSJ = getCookie('gtmjSJ');
	if (!gtmjSJ) {
		return false
	}
	gtmjSJ = gtmjSJ.split(",");
	var idx = gtmjSJ.find(id);
	if (!idx) {
		return false;
	}
	gtmjSJ.splice(idx, 1);
	$("#savedJobsCounter span").text(gtmjSJ.length);
	setCookie('gtmjSJ', gtmjSJ.toString(), 30, {
		path :"/"
	});
	$("#iframeActions iframe").attr('src', "http://62.129.149.16/remoteactions/deletesavedjob/"+id);
	//$.get("remoteactions/deletesavedjob/"+id);
	return true;
}

function check_search_form() {
	var k = document.search_form.keyword;
	var l = document.search_form.location;
	if ((k.value != '' && jQuery.trim(k.value).length >= 3)	|| (l.value != '' && jQuery.trim(l.value).length >= 3)) {
		return true;
	} else {
		alert(search_must_specify_keyword);
		return false;
	}
}
/* googleMaps */
var map = null;
var geocoder = null;
function initialize() {
	if (!GBrowserIsCompatible()) {
		return false;
	}
	map = new GMap2(document.getElementById("map_canvas"), {
		size :new GSize(400, 400)
	});
	map.setCenter(new GLatLng(51.765922, 5.526464), 7);
	map.addControl(new GSmallMapControl());
	geocoder = new GClientGeocoder();
}
function showAddress(id, address,country) {
	if (!geocoder) {
		return false;
	}
	var title = document.getElementById('jt' + id).innerHTML;
	var zoom = parseInt(address) ? 14 : 7;
	geocoder.getLatLng(address + ', '+country, function(point) {
		if (!point) {
			alert(address + " not found");
			return false;
		} else {
			map.setCenter(point, zoom);
			var marker = new GMarker(point);
			map.clearOverlays();
			map.addOverlay(marker);
			marker.openInfoWindowHtml('<strong>' + title + '</strong<br/>' + address);
		}
	});
	$('#map_canvas').dialog();
	$('#map_canvas').dialog('open');
	$('#map_canvas').dialog('option', 'autoOpen', false);
	$('#map_canvas').dialog('option', 'width', 420);
	$('#map_canvas').dialog('option', 'height', 420);
	$('#map_canvas').dialog('option', 'resizable', false);
	$('#map_canvas').dialog('option', 'modal', true);
	$('#map_canvas').dialog('option', 'bgiframe', true);
	$('#map_canvas').height(400);
}
function sure(text) {
	text = text ? text : 'Are you sure?\n\nThis action can not be undone.';
	return confirm(text);
}
