if (top.location.host=='maartenwerkenbijdeloitte.mxmm.nl')
	servernaam = 'http://maartenwerkenbijdeloitte.mxmm.nl';
else if  (top.location.host=='tim.werkenbijdeloitte.mxmm.nl')
       servernaam = 'http://tim.werkenbijdeloitte.mxmm.nl';
else
	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());
    })
    
    $('#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').delay(500).slideUp('slow');
	});
    
    
    //Social media Pim
    $('img.sm_MediaFile').each(function(i,img) {
       if( img.src.indexOf('socialmedia.php') != -1 ) {
            $(img).error(function() {
                //console.log('image could not be found');
                $(img).hide();
            })
            
            this.sQuerystring = img.src.split('?')[1];
            this.obj = (img.parentNode.tagName == 'A' && img.parentNode.className == 'sm_MediaFile') ? img.parentNode:img;
            $(this).css('padding',0);
            $(this).load(function() {
                 //   wrap object in a container with filedetails to show on mouseover
                 //   so it's clear to visitors the image is a social media photo
                $(this.obj).wrap('<div class="mp_fileInfo" />');
                this.imgContainer = $(this.obj.parentNode);
                this.imgContainer.width( $(this).width());
                this.imgContainer.height( $(this).height());
                this.imgContainer.css( 'float', 'left');
                this.imgContainer.css('margin','10px 10px 10px 0');
                $.ajax({
                    url:  servernaam+'/modules/socialmedia.php?'+this.sQuerystring.replace('t=file','t=fileinfo'),
                    context: this.imgContainer,
                    success: function(data) {
                        this.imgDetails = $(data);
                        this.imgDetails.hide();
                        $(this).append(this.imgDetails);
                        $(this).mouseover( function() {
                            //console.log($(this).find('div.mp_fileInfoDetails'), 'mouseover');
                            imgDetails = $('div.mp_fileInfoDetails',$(this));
                            imgDetails.slideDown('slow');
                            //imgDetails.shown = true; 
                            //setTimeout("if(imgDetails.hover !== true){imgDetails.slideUp('slow')};",4000);
                            setTimeout("imgDetails.slideUp('slow');",4000);
                        });
                    }
                });
            });
       }
    });
    
    /*$('div.sm_MiniGallery').each(function(m,mini) {
        $(mini).load($(mini).attr('url'), function() {
            $(mini).find('.mp_miniGalleryTitle')[0].innerHTML = ($(mini).attr('title') && $(mini).attr('title') != '') ? "Foto's: "+$(mini).attr('title'):'';
        }); 
    });*/
    $('div.sm_MiniGallery').each(function() {
        $(this).load($(this).attr('url'), function() {
            if ($(this).attr('title') && $(this).attr('title') != '')
                $('.mp_miniGalleryTitle',this).html( "Foto's: "+$(this).attr('title') );
        }); 
    });
    //einde social media                        
});

function foreignservicecallback(res,accountid){
    //console.log(res);
	$('#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 highlightmenu(doelgroep) {
    $('#nav > ul > li').removeClass('highlight2');
    $('#nav > ul > li > div').removeClass('nadeactieve');
    switch (doelgroep) {
        case 'student':
            $('#hoofdnavli8').addClass('highlight2').next().addClass('nadeactieve');
        break;
        
        case 'young professional':
            $('#hoofdnavli90').addClass('highlight2').next().addClass('nadeactieve');
        break;
        
        case 'professional':
            $('#hoofdnavli151').addClass('highlight2').next().addClass('nadeactieve');
        break;
    }
}

function roll(img_name1, img_src1) {
   document[img_name1].src = img_src1;
}
   
function trackflash(naam) {
	_gaq.push(['_trackPageview', naam]);
}

