// Necessary Js for all page on this website
/*
	Declare Global Variables
	on Load 
		Initialise for Prettyphoto
		set the Left Menu Height, 
		Reset Search Highlight
		Search Textbox OnKeyup, KeyPress 	-> call reset_highlight
		Search Submit 						-> call submitSearchForm
	
	Other Functions 
		submitSearchForm()					-> Submit SearchForm
		submitContactForm()					-> Submit ContactForm
		showform()							-> Show Div
		hideform()							-> Hide Div	
*/

// Global Variables 
var globalErr 			= 1;  // Contact Form Validation 
var SearchType 			= "partial"; //exact, whole, partial - Search method
//var searchDisplayType  	= "newpage"; // overlay =  below search textbox , newpage = on to the same page
//var searchDisplayDivId = (searchDisplayType	=="overlay")?"search_dropdown":"content";//search_dropdown = overlay below search textbox , content = same page
var searchDisplayDivId = '';

jQuery(document).ready(function() 
{

	var prev='';
	if(document.getElementById("gallery_right"))
	{
		jQuery("#gallery_right").css({height:"196px",width:"196px"});
	}
	
	$(".img_news_box").corner("round 5px");
	$(".thumb_bg_inner").corner("top 5px");
	
	//jQuery("#mainMenu li ul").hide();
	
	//jQuery("#mainMenu li[class=selected last] ul").fadeIn(500);
	//jQuery("#mainMenu li[class=selected] ul").fadeIn(500);
	//jQuery("#mainMenu li[class=selected last] ul").fadeIn(500);
	//jQuery("#mainMenu li[class=selected] ul").fadeIn(500);
	
	
	 var currentPageLiSelected = jQuery("#mainMenu").children(".selected").attr("id");

	  jQuery("#mainMenu li[class=selected last] ul").css("display","block");
	  jQuery("#mainMenu li[class=selected] ul").css("display","block");
	 
	// getting each ancher element in the main menu
	jQuery("#mainMenu>li.test").each(function(i)
	{
	// when ever the mouse over effect placed on the menu the following statements will execute	
	jQuery(this).hover(function()
	{
 	 // adding the class "selected" to the "li" element
     jQuery(this).addClass("selected");
     // giving fade in effect for the sub menu ul
     jQuery(this).find("ul").fadeIn(500);
     
      // checking the currentPageLiSelected not equals to present menu over id
     if(currentPageLiSelected != this.id)
     {
     	jQuery("#"+currentPageLiSelected+" ul").css("display","none");
	 	jQuery("#"+currentPageLiSelected).removeClass("selected");
     }
     
    
      	
     },
     function()
     {
     jQuery("#mainMenu li ul").hide();
     // removing the class "selected" to the "li" element
     jQuery(this).find("ul").fadeOut(500);
     // giving fade out effect for the sub menu ul
      jQuery(this).removeClass("selected");
      
  	// checking the currentPageLiSelected not equals to present menu over id
	 // if(currentPageLiSelected != this.id)
    // {
     	jQuery("#"+currentPageLiSelected+" ul").css("display","block");
	 	jQuery("#"+currentPageLiSelected).addClass("selected");
    // }
        	
     });
	

	  }); 
	
	
	
	
   // Contact Form Submit Form Validations
   jQuery("#contactSubmit").click(function() {	submitContactForm(); });
   jQuery("#contactReset").click(function() 
   { 
   		//document.contactForm.reset();
   });
   jQuery("#overlaySubmit").click(function() { submitContactOverlayForm(); });
   jQuery("a.close_button").click(function() 
   { 
   //alert("hi");
   //document.getElementById("overlay_bg_new").style.display="none";
	jQuery("#overlay_bg_new").css({'display':'none'});

    });
   jQuery(".thumb_inner ul li").click(function() 
   { 
   //alert("hi");
   //document.getElementById("overlay_bg_new").style.display="none";
	jQuery("#overlay_bg_new").css({'display':'block'});
	//jQuery("#producten_overlay").show();

    });
   jQuery(".downloads ul li a").click(function() 
   { 
   //alert("hi");
   //document.getElementById("overlay_bg_new").style.display="none";
	jQuery("#overlay_bg_new").css({'display':'block'});

    });
   
	   
 });
 
 // Function used to get the portfolio project details
   function getPortfolioProjectDetails(proj_id,cat_id)
   {
   		jQuery.ajax(
			{    
				type: "post", 
				url: W3FE_SITE_URL+"_includes/cmsPortfolioProject.php",
				data: {proj_id:proj_id,cat_id:cat_id},
				success: function(msg)
				{
					showOverlay("producten_overlay");	
					jQuery("#inner_overlay").html(msg);
					jQuery("#producten_overlay").show();
				} 
	
			 });// End of Request 
   }
 
 
// validate, submit overlay Contact Form
function submitContactOverlayForm()
{
		pdf_file_name = document.getElementById("pdf_name").value;
		
		// Check for Empty
		w3isEmpty("contactName1","","");
		w3isEmpty("contactEmail1","","");
			
		// For Invalid Email id, display text message
		w3isEmail("contactEmail1","contactEmail_err1","e-mail is niet geldig");
		//alert(globalErr);
		if (globalErr==1)
		{
			// Hiding the error message
			hideform("contactErrorMessage1");
			jQuery.ajax(
			{    
				type: "get", 
				url: "_includes/_emails/overlaySendMail.php", 
				data: jQuery("#contactForm1").serialize(),
				success: function(msg)
				{ 	
					//alert(msg);
					closeOverlay('contact_overlay');	
					jQuery("#overlay_bg_new").css({'display':'none'});
					contactFormReset('contactReset1');
					window.location.href =W3FE_SITE_URL+"/_includes/_emails/downloadFile.php?name="+pdf_file_name;
					
					//download_file(pdf_file_name);
				} 
	
			 });// End of Request 
		}
		else
		{
			showform("contactErrorMessage1");
		}
	
		globalErr = "1"; // reset to no error
		
}
// validated, Submit Contact Form
function submitContactForm()
{
		// Check for Empty
		w3isEmpty("contactName","","");
		w3isEmpty("contactPhone","","");
		w3isEmpty("contactEmail","","");
			
		// For Invalid Email id, display text message
		w3isEmail("contactEmail","contactEmail_err","e-mail is niet geldig");
		w3isTelephone("contactPhone","contactTelephone_err","please enter valid phone");
		//w3isTelephone("contactPhone");
		//alert(globalErr);
		if (globalErr==1)
		{
			hideform("contactErrorMessage");
			showform("contactFormLoader");
			
			jQuery.ajax(
			{    
				type: "post", 
				url: "_includes/_emails/contactSendMail.php", 
				data: jQuery("#contactForm").serialize(),
				success: function(msg)
				{ 	
					//alert(msg);	
					hideform("contactFormLoader");
					showform("contactFormMessage");
					// Clear the Form Values
					contactFormReset('contactReset');
					//document.contactForm.reset();
					
				 } 
	
			 });// End of Request 	
	
		}
		else
		{
			
			showform("contactErrorMessage");
			
		}
	
		globalErr = "1"; // reset to no error

		
}

// Function to get more 5 news
function getNewsMore(limit,lang)
{
	jQuery.ajax(
			{    
				type: "post", 
				url: "_includes/getNewsMore.php", 
				data: { limit:limit, lang:lang},
				success: function(msg)
				{ 
					jQuery(".middle_container").html(msg);	
					//alert(msg);	
				 } 
	
			 });// End of Request 
}


// Clear the Contact Form Field Values
function contactFormReset(id)
{
	jQuery("#"+id).click();
}

//clear clearSearchForm
function clearSearchForm()
{
	// Empty the Textbox
	jQuery("#sKey").attr("value","");
	
	// call the search to update the search key
	 submitSearchForm('searchClearClear');
	 
	 if (searchDisplayType=="overlay")
	 {
	 	if (!jQuery("#"+searchDisplayType).hasClass("hide")) 
	 		jQuery("#"+searchDisplayType).addClass("hide");
	 }
}

// Show div
function showform(id)
{
	document.getElementById(id).style.display="block";
}

// Hide Div
function hideform(id)
{
	document.getElementById(id).style.display="none";
}

function showLanguageDropdown()
	{
	if(!jQuery("#language_dropdown").hasClass('show'))
		{
		//document.getElementById("language_dropdown").style.display="block";
	 	jQuery("#language_dropdown").removeClass("hide");
	 	jQuery("#language_dropdown").addClass("show");
		}
	}
	
function hideLanguageDropdown()
	{
	if(!jQuery("#language_dropdown").hasClass('hide'))
		{
		//document.getElementById("language_dropdown").style.display="block";
	 	jQuery("#language_dropdown").removeClass("show");
	 	jQuery("#language_dropdown").addClass("hide");
		}
	}
	
	
//*******************************************AVEDKO Javascript***************************************//

//Front end Java Script File
// JavaScript Document
jQuery(document).ready(function(){
  var rand_time = randomXToY(6,12)*1000;
  var rand_time_second = randomXToY(6,12)*1000;
  		  
  jQuery('#slide_show').cycle({ 
   timeout:rand_time, 
    random:  1
  });
  //
 jQuery('#referenties').cycle({ 
   timeout:rand_time_second, 
    random:  1
  });
 
 //initialize();

});

function initialize() {
	  if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("map_canvas"));
	   map.setCenter(new GLatLng(51.80055,4.64478), 17);
		var center = new GLatLng(51.80055,4.64478);
		//removing hybrid map type
		//map.removeMapType(G_HYBRID_MAP);
		//adding terrain
		//map.addMapType(G_PHYSICAL_MAP);
		//removing hybrid
		//map.removeControl(G_HYBRID_MAP);
		var marker = new GMarker(center, {draggable: true});
		map.addOverlay(marker);
		/*map.openInfoWindow(map.getCenter(),
		document.createTextNode("Tolstraat 132-134 1074 ZV Amsterdam"));*/
		map.addControl(new GSmallMapControl());
		var mapControl = new GMapTypeControl();
		map.addControl(mapControl);
		  // Create a base icon for all of our markers that specifies the
		// shadow, icon dimensions, etc.
		var baseIcon = new GIcon(G_DEFAULT_ICON);
		baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
		baseIcon.iconSize = new GSize(20, 34);
		baseIcon.iconAnchor = new GPoint(9, 34);
		baseIcon.infoWindowAnchor = new GPoint(9, 2);

		// Creates a marker whose info window displays the letter corresponding
		// to the given index.
		function createMarker(point, index) {
		  // Create a lettered icon for this point using our icon class
		  var letter = String.fromCharCode("A".charCodeAt(0) + index);
		  var letteredIcon = new GIcon(baseIcon);
		  letteredIcon.image = "http://www.google.com/mapfiles/marker" + letter + ".png";

		  // Set up our GMarkerOptions object
		  markerOptions = { icon:letteredIcon };
		  var marker = new GMarker(point, markerOptions);
       		 //var marker = new GMarker(point, baseIcon);
		  GEvent.addListener(marker, "click", function() {
			//marker.openInfoWindowHtml("Hoogeveenenweg 212<br />2913 LV Nieuwerkerk a/d IJssel<br />");
			marker.openInfoWindowHtml("<div class='address'><b><a target='_parent' href='http://maps.google.com/maps?f=q&source=s_q&hl=nl&geocode=&q=avedko+bv+avedko.nl&sll=51.800537,4.644775&sspn=0.009886,0.027895&ie=UTF8&latlng=51800537,4644775,18207359844385561795&ei=l7fUSeyfAoPmuQPAy-ChDg&sig2=F0C3j5KBlI6o9jnuGVNFzw&cd=1'>Avedko BV</a></b><br /><span class='rev'><a href='/maps?f=q&source=s_q&hl=nl&geocode=&q=avedko+bv+avedko.nl&sll=51.800537,4.644775&sspn=0.009886,0.027895&ie=UTF8&latlng=51800537,4644775,18207359844385561795&ei=xLrUSYHSMoPmuQPAy-ChDg&sig2=zFyfRqOdK-NkMCzPPiJUsw&cd=1&dtab=2'>Een recensie schrijven</a> - </span><br />Nijverheidstraat 8 <br/>3316 AP Dordrecht, Netherlands <br/> 078 6333444<br /><a class='whome_page' target='_parent'  href='http://www.avedko.nl/'>avedko.nl</a><br/><span class='route_links'>Routebeschrijving:<a href='javascript:void(0);'>Hier naartoe</a> - <a href='javascript:void(0);'>Hier vandaan</a> - <a href='javascript:void(0);'>In de buurt zoeken</a></span></div>");
		  });
		  return marker;
		}
			// Add 10 markers to the map at random locations
			var bounds = map.getBounds();
			var southWest = bounds.getSouthWest();
			var northEast = bounds.getNorthEast();
			var lngSpan = northEast.lng() - southWest.lng();
			var latSpan = northEast.lat() - southWest.lat();
			for (var i = 0; i < 1; i++) {
			  var point = new GLatLng(southWest.lat() + latSpan * Math.random(),
									  southWest.lng() + lngSpan * Math.random());
			  map.addOverlay(createMarker(center, i));
			}
	
	  }
	}
	

//function to get random number upto m
function randomXToY(minVal,maxVal,floatVal)
{
  var randVal = minVal+(Math.random()*(maxVal-minVal));
  return typeof floatVal=='undefined'?Math.round(randVal):randVal.toFixed(floatVal);
}

var browserName=navigator.appName; 


function showOverlay(id,temp)
	{
	
	$("#pdf_name").val(temp);
	var totalHeight = document.documentElement.scrollHeight;
	jQuery(".overlay_bg").css({'height':totalHeight+"px"});

	if (browserName=="Microsoft Internet Explorer")
	 {
	document.getElementById(id).style.display="block";
	 }
	 //jQuery("#"+id).fadeIn("fast");
	jQuery("#"+id).fadeIn(700);
	}

function closeOverlay(id)
	{
	if (browserName=="Microsoft Internet Explorer")
	 {
	document.getElementById(id).style.display="none";
	 }
	//jQuery("#"+id).fadeOut("fast");
	jQuery("#"+id).fadeOut(300);
	}
	
function get_page(id)
{

	window.location.href =W3FE_SITE_URL+id;
	
}

