var s2af = function() {
	$('#s2af .form').css('opacity','0.9').hide();
	$('#s2af a').attr('href','#').css('cursor','pointer').click(function (i) {
		$('#s2af .form').slideToggle();
		return false;
	});
	$('#s2af button').click(function (i) {
		alert('Mail verstuurd!');
		$('#s2af .form').hide();
		return false;
	});
}




/* helpers */

var prefill = function() {
	$('.prefill').each(function (i) {
		if (this.title)
			var txt = '('+this.title+')';
		else
			var txt = '(Typ uw zoekwoorden in dit veld)';
		$(this).attr('value', txt).focus(function () {
			if (this.value == txt)
				this.value = '';
		}).blur(function () {
			if (this.value == '')
				this.value = txt;
		});
	});
}
//http://www.iknowkungfoo.com/blog/index.cfm/2008/7/9/Check-All-Checkboxes-with-JQuery
var checkAll = function() {
	$('.check-all input').click(function () {
		var chk = this.checked;
		$(this.parentNode.parentNode.getElementsByTagName('input')).each(function (i) {
			this.checked = chk;
		});
	});
}

var externalLinks = function() {
	var hostname = window.location.hostname;
	hostname = hostname.replace("www.","").toLowerCase();
	var a = document.getElementsByTagName("a");	
	this.check = function(obj){
		var href = obj.href.toLowerCase();
		return (href.indexOf("http://")!=-1 && href.indexOf(hostname)==-1 && href.indexOf('realworks.nl')==-1) ? true : false;				
	}
	this.set = function(obj){
		obj.target = "_blank";
		obj.className += " external";
		obj.title += ' (opent in een nieuw scherm)';
	}
	$('.container a').each(function () {
		if(check(this)) set(this);
	});		
}

function smoothAnchors() {
	$('a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
		&& location.hostname == this.hostname) {
			var h = this.hash;
			var $target = $(this.hash);
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				$('html,body').animate({scrollTop: targetOffset}, 750, function(){
					document.location.hash = h;
				});
				return false;
			}
		}
	});
}

/*Equalize colums height*/
(function($) {
	/**
	 * equalizes the heights of all elements in a jQuery collection
	 * thanks to John Resig for optimizing this!
	 * usage: $("#col1, #col2, #col3").equalizeCols();
	 */
	 
	$.fn.equalizeCols = function(){
		var height = 0,
			reset = $.browser.msie ? "1%" : "auto";
  
		return this
			.css("height", reset)
			.each(function() {
				height = Math.max(height, this.offsetHeight);
			})
			.css("height", height)
			.each(function() {
				var h = this.offsetHeight;
				if (h > height) {
					$(this).css("height", height - (h - height));
				};
			});
			
	};
	
})(jQuery);

/*Equalize colums height*/



$(document).ready(function() {
	externalLinks();
	smoothAnchors();
	prefill();
	checkAll();
	s2af();
	 // http://malsup.com/jquery/cycle/lite/

    // for equal Colums
//    $(".leftCol, .midCol, .rightCol, .midColBig").equalizeCols();
    $(".homeBottomLeftCol , .homeBottomCenterCol, .homeBottomRightCol").equalizeCols();
    //$(".imageResultCont").equalizeCols();
    //$(".textResultCont, .textResultCont").equalizeCols();
    
    // for Main Menu
	$('li.headlink').hover(
		function() { $('ul.level1', this).css('display', 'block'); },
		function() { $('ul.level1', this).css('display', 'none'); });
	
	$('li.mainLinks').hover(
		function() { $('ul.menuLevel1', this).css('display', 'block'); },
		function() { $('ul.menuLevel1', this).css('display', 'none'); });	    

     
    // goes up in the above function $("li.mainLinks").css('background-position', 'bottom');
    
   $('li.searchSortLink').hover(
		function() { $('a.sortPeriodLink').css({'border': '1px solid #73B0C0', 'border-bottom':'0px'}); },
		function() { $('a.sortPeriodLink').css('border', '0'); });
  
    $('li.searchSortLink').hover(
		function() { $('ul.level1', this).css('display', 'block'); },
		function() { $('ul.level1', this).css('display', 'none'); });
		
	 $('li.parentMenu').hover(
		function() { $('ul.level1', this).css('display', 'block'); },
		function() { $('ul.level1', this).css('display', 'none'); });
	 
	 $('li.parentMenu').hover(
		function() { $('li.showEmailDropdown').css({'border': '1px solid #73B0C0', 'border-bottom':'0px', 'font-weight':'bold'}); },
		function() { $('li.showEmailDropdown').css({'border': '0', 'font-weight':'normal'}); });

	//hover over partners logo on home page
/*	 $('div.partnersCont img').hover(
		function() { $(this).css('border-color', '#ffffff'); },
		function() { $(this).css('border-color', '#46302A'); });*/
		
  	var originalImagePath = '';
  	var lightUpImagePath = '';
 	$('.partnersCont img').hover(
 		function() { 
	    	originalImagePath = $(this).attr("src");
	    	lightUpImagePath = $(this).attr("longdesc");
			$(this).css('border-color', '#ffffff');
	    	$(this).attr({ src: lightUpImagePath}); 
	    },
	    function() {
			$(this).css('border-color', '#46302A');
	    	$(this).attr({ src: originalImagePath});
 	    }
	);
	
	$("div.paginationCont b").mouseover( function(){
		$(this).css({'color': '#ca1919', 'background':'#ffffff'});
    });

    $("div.paginationCont b").mouseout( function(){
		$(this).css({'color': '#46302A', 'background':'#CFE5EA'});
    });
    $("div.paginationCont b.currentPage").mouseout( function(){
		$(this).css({'color': '#ffffff', 'background':'#73B0C0'});
    });
     $("div.paginationCont b.previousLink").mouseout( function(){
		$(this).css({'color': '#ffffff', 'background':'#73B0C0'});
    });
     $("div.paginationCont b.nextLink").mouseout( function(){
		$(this).css({'color': '#ffffff', 'background':'#73B0C0'});
    });
  	
    //For Faq toggle sliding
    $("div.questionFAQ").click(function () {
    	$("div.answerFAQ").hide("fast");
        $(this).next('div.answerFAQ').slideToggle('fast');
        //$("div.answerFAQ").slideToggle("slow");
     });
     
     $("a.expandAll").click(function () {
        $("div.answerFAQ").show("fast");
     });
     
     $("a.collapseAll").click(function () {
        $("div.answerFAQ").hide("fast");
     });
     
   var ctr =1;
   var defaultHeightLeftCol = $("div.leftCol").height();
   var defaultHeightMidCol = $("div.midCol").height();
   var defaultHeightRightCol = $("div.rightCol").height();
   
/*   $("span.zoomLevel2").mouseover( function(){
	$(this).css("color", "#ca1919");
   });

   $("span.zoomLevel2").mouseout( function(){
	$(this).css("color", "#fff");
   });

   $("span.zoomLevel1").mouseover( function(){
	$(this).css("color", "#ca1919");
   });

   $("span.zoomLevel1").mouseout( function(){
	$(this).css("color", "#fff");
   });  */
   
   $("span.zoomLevel2").click( function(){
         if (ctr==1)
         {
            $('body').removeClass("biggerFont");
            $('body').addClass("bigFont");
          /*  $('div.leftCol').height($('div.leftCol').height()+30);
            $('div.midCol').height($('div.midCol').height()+30);
            $('div.rightCol').height($('div.rightCol').height()+30);*/
            ctr++;
          }
          else if (ctr==2)  
          {   
            $('body').removeClass("bigFont");
            $('body').addClass("biggerFont");
/*            $('div.leftCol').height($('div.leftCol').height()+30);
            $('div.midCol').height($('div.midCol').height()+30);
            $('div.rightCol').height($('div.rightCol').height()+30);*/
           } 
	});
        
     $("span.zoomLevel1").click (function(){
           $('body').removeClass();
           $('body').addClass("normalFont");
/*           $('div.leftCol').height(defaultHeightLeftCol);
           $('div.midCol').height(defaultHeightMidCol);
           $('div.rightCol').height(defaultHeightRightCol);*/
           ctr=1;
    });
	
	//Advance search Panel Toggle
	$("div.advanceSearchLink span").click (function(){
		$('.advanceSearchOptions').css("display","block");
		$('.mainSearchBox').css("display","none");
		$('.leftMenuCont').css("padding","60px 0 66px 0");
		
	});	

});
$(window).load(function() {

});
$(document).resize(function() {

});

//For Maps



// Function for Display All Search Result
	function displayAllResults(fwd,typeOfResult)
	{
		//Used root path from sIfRCustomise.js
		document.forms['SearchForm'].allResultsType.value = typeOfResult
		document.forms['SearchForm'].action = rootPath + fwd;
		document.forms['SearchForm'].submit();
	}

// Function for Display All Search Result From Collection or Period Sort
	function allResultsFromSortPage(fwd,typeOfResult,name,sortType)
	{
		//Used root path from sIfRCustomise.js
		document.forms['SearchForm'].allResultsType.value = typeOfResult
		document.forms['SearchForm'].collectionOrPeriodName.value = name;
		document.forms['SearchForm'].sortType.value = sortType;
		document.forms['SearchForm'].action = rootPath + fwd;
		document.forms['SearchForm'].submit();
	}
	
//	Function for Serch In Contact us Page
	function search(fwd)
	{
		//Used root path from sIfRCustomise.js
		document.forms['SearchForm'].action = rootPath + fwd;
		document.forms['SearchForm'].submit();
	}

//	Function for Serch with reset Form
	function searchWithResetForm(fwd)
	{
		document.forms['SearchForm'].sortType.value = true;
		document.forms['SearchForm'].action = fwd;
		document.forms['SearchForm'].submit();
	}	
	
// Search Checkbox Function
$(document).ready(function() {
		
		$("input.selectall").click(function(){	
			//Found mixed Javascript and HTML	
			disableAllOption(this);
			var selParent = $(this).parent("div").parent("li").parent("ul.level1").attr("id");
			$('#show'+ this.id).toggle();
			// Set Varible for Deselect SelectAll Option
			if($('#'+selParent+' input.selectall').attr('checked')==false){
					addDisableValueDeselectAll(this);
			}
			
			$('#'+selParent+' input.selectItem').each(function() {
				this.checked = $('#'+selParent+' input.selectall').attr('checked'); 
				//Unset the of deselected Varable if SelectAll is unselect .
				if($('#'+selParent+' input.selectall').attr('checked')==false){
					addDisableValueDeselectAll(this);
				}				
				$('#show'+ this.id).hide(); 
			});
		});
		
		$("input.selectItem").click(function(){			
			var selParent = $(this).parent("div").parent("li").parent("ul.level1").attr("id");			
			addDisableValue(this);
			document.getElementById($('#'+selParent+' input.selectall').attr('id')).checked = false;
			
			// Changes for Select All Issue
			addDisableValueDeselectAll(document.getElementById($('#'+selParent+' input.selectall').attr('id')));
			
			$('#show' + $('#'+selParent+' input.selectall').attr('id')).hide();
			
				$('#'+selParent+' input.selectItem').each(function() { 
					if(this.checked) {
						$('#show'+ this.id).show(); 
					//	$('div.mainContent').height($('div.mainContent').height()+25);
					}
					else 
						$('#show'+ this.id).hide(); 
				});
			
				if(this.checked)
				{
					$('#show'+ this.id).show();
				//	$('div.mainContent').height($('div.mainContent').height()+10);		
					
				}	
				else
				{
					$('#show'+ this.id).hide();
				//	$('div.mainContent').height($('div.mainContent').height()-10);		
				}	
			
				
		});
		
		$("div.xSelectAll INPUT[type='button']").click(function()
		{
			hideOption(this,true);

		});
		$("div.xSelect INPUT[type='button']").click(function()
		{
			hideOption(this);

		});
		
		// Disable Select All Option of checkbox.
		function disableAllOption(element){
			if(element.checked != true){
				document.forms['SearchForm'].elements[element.name].value = false;
				//document.getElementById("list1").name;
			}
		}
	});
	
	function showDefaultChecked()
	{
		
		
		$("ul.filterDropDown input.selectItem").each(function()
		{
			if(this.checked) {
				//$('div.mainContent').height($('div.mainContent').height()+25);
				$('#show'+ this.id).show(); 
			}
			else 
				$('#show'+ this.id).hide();
			
		});

		$("ul.filterDropDown input.selectall").each(function()
		{
			
			if(this.checked) {
				
				var selParent = $(this).parent("div").parent("li").parent("ul.level1").attr("id");
				$("#" + selParent + "Show div").hide();
				$('#show'+ this.id).show(); 
				//$('div.mainContent').height($('div.mainContent').height()-15);
			}
			else 
				$('#show'+ this.id).hide();
			
		});

	
	}
	
	function hideOption(xButton,hideAll)
	{	
		var parentEle = $(xButton).parent("div")
		$(parentEle).hide();
		var cid = parentEle.attr('id').substr(4,parentEle.attr('id').length-1);
		document.getElementById(cid).checked = false;
		
		//Unset the of deselected Varable if SelectAll is unselect .
		addDisableValueDeselectAll(document.getElementById(cid));
		
		//$('div.mainContent').height($('div.mainContent').height()-10);
		if(hideAll)
		{
			var le = $('#'+cid).parent('div').parent("li").parent("ul").attr('id');			
			$('#'+le+' input').each(function() { 
				this.checked = false;
				addDisableValueDeselectAll(this);
			 });
			//$('div.mainContent').height($('div.mainContent').height()-10);
		}
	}
	
// Set Disabled Checkboxes
	function addDisableValue(ele){
		var elementName = ele.name;
		var myNameList = elementName.split ( '.' );
		if(ele.checked != true){
			document.forms['SearchForm'].disableValues.value = document.forms['SearchForm'].disableValues.value + myNameList[0] + '.';
		}else{
			if(document.forms['SearchForm'].disableValues.value.length > 0){
				var myString = document.forms['SearchForm'].disableValues.value;
				var myPropertyList = myString.split ( '.' );
				document.forms['SearchForm'].disableValues.value = "";
				for(var i=0;i < myPropertyList.length;i++) {
					if(myPropertyList[i]!= myNameList[0]){
						document.forms['SearchForm'].disableValues.value = document.forms['SearchForm'].disableValues.value + myPropertyList[i] + '.';
					}
				}
			}
		}
	}
	

 
 
 // Set Disabled Checkboxes by Deselect All or Remove one by one Selected
	function addDisableValueDeselectAll(ele){
		var elementName = ele.name;
		var myNameList = elementName.split ( '.' );
		// If already present in the List then remove it.
		if(document.forms['SearchForm'].disableValues.value.length > 0){
			var myString = document.forms['SearchForm'].disableValues.value;
			var myPropertyList = myString.split ( '.' );
			document.forms['SearchForm'].disableValues.value = "";
			for(var i=0;i < myPropertyList.length;i++) {
				if(myPropertyList[i]!= myNameList[0]){
					document.forms['SearchForm'].disableValues.value = document.forms['SearchForm'].disableValues.value + myPropertyList[i] + '.';
				}
			}
		}
		document.forms['SearchForm'].disableValues.value = document.forms['SearchForm'].disableValues.value + myNameList[0] + '.';
		
 	}

/* Home Image Gallery*/	

$(document).ready(function() {
	var timeCtr=0;
	$('#slideshowHome').cycle({
		fx: 'fade',
        timeout: 5000,
        pager: '#navGallery',
        pagerEvent: 'click',
        speed:1000
    });	
	 $('#slideshowHome').cycle('pause'); 
	 
      $('.playButton').click(function() { 

      	if (timeCtr == 1)
      		{	
		        $('#slideshowHome').cycle('resume');
		        timeCtr=0;
	        }
	    else if (timeCtr == 0)   
	    	{
		        $('#slideshowHome').cycle('resume');
		        $('#slideshowHome').cycle(0);
	        }
	    $('img.playButton').css("display","none");
   	    $('img.playButton').css("visibility","hidden");
	        
      });
	
	$('#pauseButton').click(function() { 
        $('#slideshowHome').cycle('pause'); 
        $('img.playButton').css("display","")
        timeCtr = 1;
    });
	
	$('#resumeButton').click(function() { 
        if (timeCtr == 1)
      		{	
		        $('#slideshowHome').cycle('resume');
		        timeCtr=0;
	        }
	    else if (timeCtr == 0)   
	    	{
		        $('#slideshowHome').cycle('resume');
		        $('#slideshowHome').cycle(0);
	        }
	    $('img.playButton').css("display","none");
   	    $('img.playButton').css("visibility","hidden");
        
    });

	$('#stopButton').click(function() { 
        $('#slideshowHome').cycle('pause'); 
        $('#slideshowHome').cycle(0); 
        $('img.playButton').css("display","");
        timeCtr = 0;
    });

});

/* Home Image Gallery End*/	

/*Story page Image gallery*/

$(function() {

	$('#pauseIVButton').click(function() { 
        $('#bigImage').cycle('pause'); 
    });
	
	$('#resumeIVButton').click(function() { 
        $('#bigImage').cycle('resume',true); 
        
    });
	$('#stopIVButton').click(function() { 
	    $('#bigImage').cycle('pause'); 
        $('#bigImage').cycle(0); 
    });

	$('#bigImage').cycle({
      	fx:     'fade',
      	speed:  'slow',
      	timeout: 4000
    	});

	$('.thumbCont').cycle({
      	fx:     'fade',
      	speed:  'slow',
      	timeout: 0,
		pager:  '#thumbNumber',
		prev:    '#prevSlide',
		next:    '#nextSlide'
    });
	
	$(".thumbCont img").click(function() { 
		var tId = $(this).attr('id');
	    var imgThumbId= tId.substr(5,2) -1;
		//alert(imgThumbId);
		$('#bigImage').cycle('pause'); 
		$('#bigImage').cycle(imgThumbId); 
		
    });
	
//	$(".leftCol, .midCol, .rightCol, .midColBig").equalizeCols();
});
/*Story page Image gallery End*/

// Assing Lower SearchKey to Upper SearchKey.
function assignValue(ele){
	document.getElementById('upperSearchKey').value = ele.value;
}

// Pagination for Search Results.
function getPageContent(pageClicked,fwd){
	var pageSelected = parseInt(pageClicked);
	document.forms['SearchForm'].pageOffset.value = (pageSelected-1)*10;
	document.forms['SearchForm'].currentPage.value = pageSelected;
	
	//Used root path from sIfRCustomise.js
	document.forms['SearchForm'].action = rootPath + fwd;
	document.forms['SearchForm'].submit();
}

function prevOrNextPage(type,fwd){
	if('prev'==type){
		document.forms['SearchForm'].currentPage.value =parseInt(document.forms['SearchForm'].currentPage.value) - 1;
		document.forms['SearchForm'].pageOffset.value =parseInt(document.forms['SearchForm'].pageOffset.value) - 10;
		if( parseInt(document.forms['SearchForm'].startPage.value) > 1){
			document.forms['SearchForm'].startPage.value = parseInt(document.forms['SearchForm'].startPage.value) - 1;
			document.forms['SearchForm'].lastPage.value = parseInt(document.forms['SearchForm'].lastPage.value) - 1;
		}
	}else if('next'==type){
		document.forms['SearchForm'].currentPage.value =parseInt(document.forms['SearchForm'].currentPage.value) + 1;
		document.forms['SearchForm'].pageOffset.value =parseInt(document.forms['SearchForm'].pageOffset.value) + 10;
		if(parseInt(document.forms['SearchForm'].lastPage.value) < parseInt(document.forms['SearchForm'].totalPages.value) ){
			document.forms['SearchForm'].startPage.value = parseInt(document.forms['SearchForm'].startPage.value) + 1;
			document.forms['SearchForm'].lastPage.value = parseInt(document.forms['SearchForm'].lastPage.value) + 1;
		}
	}
	//Used root path from sIfRCustomise.js
	document.forms['SearchForm'].action = rootPath + fwd;
	document.forms['SearchForm'].submit();
}

function externalLinks_new_window() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
} 

window.onload = externalLinks_new_window; 

//landkaart map marker js
function showMarkers(markers){
	for(var i=0; i<markers.length;i++){
		markers[i].show();
	}
}

function hideMarkers(markers){
	for(var i=0; i<markers.length;i++){
		markers[i].hide();
	}
	map.closeInfoWindow();
}
