servernaam = 'http://www.werkenbijdeloitte.nl';

$(function(){
	if (homepage) {
		$('#nav>ul>li').hover(
			function(){
				$('div',this).show();
				$(this).next().addClass('nadeactieve');
			},
			function(){
				$('.subnavdiv').hide();
				$(this).next().removeClass('nadeactieve');
			}
		);
	} else {	
		$('#submenu>ul>li').hover(function(){
				$('div',this).show();
				$(this).next().addClass('nadeactieve');
				if (oudeIE)
					$('#map').hide();
			},
			function(){
				$('#submenu>ul>li>div').hide();
				$(this).next().removeClass('nadeactieve');
				if (oudeIE)
					$('#map').show();
		});	
		if (!oudeIE) {
			$('.submenurechterkant').each(function(){
				$(this).height($(this).parent().height());
				$(this).css('left',$(this).parent().width());
			});		
		}
	}
    //reacties:
    validation = $('#formreacties').validate();
    
    
    $('.linkreacties').click(function(){
        $('.socialfooterdiv').hide();
        $('#divreacties').slideDown();
        return false;
    })
               
    $('#formreacties').live('submit', function() {
        if ($('#formreacties').valid()) {
            data = $('#formreacties').serializeArray();
            $('#divplaatsreactie').html('<img src="/img/ajax-loader.gif" />');
            $('#divreacties').load('/ajax/plaatsreactie.php',data);
        }
        return false;
    });
    
	$('#signinwith').click(function(){
        window.open('/foreignservice.php?serviceid='+$('#foreignservice').val()+'&contentid='+$('#contentid').val());
    })
    
    $('#foreignservice').change(function() {
		var serviceid = $('#foreignservice').val();
		var fsname = $('#fs'+serviceid).val();
		if(serviceid==1){
			$('#divplaatsreactie').show();
			$('#meldingkiesmethode').hide();
			$('.validform').hide();
            $('#reactiesemailadressterretje').show();
            $('#reactiesemailadres').addClass('required');
		}else if(serviceid>1){
			$('#meldingkiesmethode').hide();
			$('#divplaatsreactie').hide();
			$('#signinwith').attr('src','/img/signinwith'+fsname+'.png')
			$('.validform').show();
            $('#reactiesemailadressterretje').hide();
            $('#reactiesemailadres').removeClass('required');
		}else{
			$('.validform').hide();
			$('#meldingkiesmethode').show();
			$('#divplaatsreactie').hide();
            $('#reactiesemailadressterretje').hide();
            $('#reactiesemailadres').removeClass('required');
		}
		
		$("#fserviceid").val(serviceid);
	});
    
    //einde reacties    
	$('.subhomehighlight','#subcon1').mouseover(function(){
		$('.subhomehighlight').removeClass('actief');
		$('.subhomehighlightvisual','#subflaban').hide();
		nummer =  $(this).attr('id').substring(16);
		$('#subhomehighlightvisual'+nummer,'#subflaban').show();
		$('#subhomehighlight'+nummer).addClass('actief');
	});
	$('#zoekboxinput, #vacaturezoekveld, #evenementzoekveld, #insidedeloittezoekveld').clearonfocus();
	$('#zoekboxinput').keyup(zoekboxzoeken);
	$('#zoekboxdiv').click(zoekboxzoeken);
	$('#zoekboxinput').blur(function(){
		$('#zoekresultatendivcontainer').slideUp('slow');
	});
});

function foreignservicecallback(res,accountid){
	$('#divplaatsreactie').show();
	$('#descmethods').hide();
	$('.validform').hide();
	$("#foreignserviceaccountid").val(accountid);
	$("#reactiesnaam").val(res.screen_name);
	if(res.profile_image_url!=''){
		$("#reactiesfototr").show();
		$("#reactiesfotoimg").attr('src',res.profile_image_url);
		$("#reactiesfoto").val(res.profile_image_url);
	}
	if(res.url!=''){
		$("#reactieswebsite").val(res.url);
	}
}

function zoekboxzoeken() {
	if ($('#zoekboxinput').val().length>1 && $('#zoekboxinput').val()!='Zoeken') {
		$('#zoekboxdiv').css('background-image','url('+servernaam+'/img/zoekboxloader.gif)');
		//$('#zoekresultatendiv').load(servernaam+'/ajax/zoekbox.php',{text:$('#zoekboxinput').val()},function(){
		$.getJSON(servernaam+'/ajax/zoekbox.php?_callback=?',{text:$('#zoekboxinput').val()},function(data){
				$('#zoekresultatendiv').html(data.item);			
				$('#zoekresultatendivcontainer').slideDown('slow');
				$('#zoekboxdiv').css('background-image','url('+servernaam+'/img/zoekbox.gif)');
		});
	} else
		$('#zoekresultatendivcontainer').slideUp('slow');
}

function anderenbezochtenook(cid) {
    $('.socialfooterdiv').hide();
	$('#divanderenbezochtenook').slideDown().load('/ajax/anderenbezochtenook.php',{cid:cid},function(){
		$('.anderenbezochtenookbloklink').hover(function(){
			$(this.firstChild).attr("src", '/img/pageiconhover.gif');
		},function(){
			$(this.firstChild).attr("src", '/img/pageicon.gif');
		})	
	});
    return false;
}

jQuery.fn.clearonfocus = function() {
	jQuery(this)
	.bind('focus', function() {
		if (this.value.indexOf('Zoek')!=-1) {
			// Set the default value if it isn't set
			if ( !this.defaultValue ) this.defaultValue = this.value;
			// Check to see if the value is different
			if ( this.defaultValue && this.defaultValue != this.value ) return;
			// It isn't, so remove the text from the input
			this.value = '';
		}
	})
	.bind('blur', function() {
		if (this.defaultValue.indexOf('Zoeken')!=-1) {
			// If the value is blank, return it to the defaultValue
			if ( this.value.match(/^\s*$/) )
				this.value = this.defaultValue;	
		}	
	});
};

jQuery.preloadImages = function() {
  for(var i = 0; i<arguments.length; i++) {
    jQuery("<img />").attr("src", arguments[i]);
  }
}
/*
jQuery.extend(jQuery.validator.messages, {
	required : 'Dit is een verplicht veld.'
});*/


function roll(img_name1, img_src1)
   {
   document[img_name1].src = img_src1;
   }

