function Link(div, tar){
	$(div).load(tar, function()
	  {$(div).find('a');}
	);
}

//Shows greyout
function show_greyout (){
	$('#greyout').removeClass('hidden');
	return false;

}
//Hides greyout
function hide_greyout (){
	$('#greyout').addClass('hidden');
}

$(document).ready(function(){
	
	//Pirobox Gallery Plugin:
	$().piroBox({
				my_speed: 300, //animation speed
				bg_alpha: 0.5, //background opacity
				radius: 4, //caption rounded corner
				scrollImage : true, // true == image follows the page _|_ false == image remains in the same open position
														 // in some cases of very large images or long description could be useful.
				slideShow : 'true', // true == slideshow on, false == slideshow off
				slideSpeed : 3, //slideshow duration in seconds(3 to 6 Recommended)
				pirobox_next : 'piro_next', // Nav buttons -> piro_next == inside piroBox , piro_next_out == outside piroBox
				pirobox_prev : 'piro_prev', // Nav buttons -> piro_prev == inside piroBox , piro_prev_out == outside piroBox
				close_all : '.piro_close' // add class .piro_overlay(with comma)if you want overlay click close piroBox
	});

	//Cycle Plugin:
	$('#slideshow1').cycle(
		{
			timeout:	6000,
    	speed:		2000,
			pause:		true
		}
	);

	//Click the Header
	$('#weathermaster_ie').click( function(){	window.location = "http://www.weathermaster.ie"; return false; });
	
	//Energy rating - show more info:
	
	//$('#rating_more').click (	function(){	$('#energy_rating_more').toggle("slow"); return false;}		);
	$('#rating_more').toggle (	function(){	$('#energy_rating_more').fadeIn("slow"); 
														//$(this).fadeOut("slow"); 
														$(this).html("Hide energy rating information");
														return false;},
														
														function() { $('#energy_rating_more').fadeOut("slow"); 
														$(this).html("More about energy rating");
														return false; }
														);
	
	//Click 'get a quote':
	$('.popup_form_trigger').click( function(){	show_greyout(); $('#popup_form').show("slow"); return false;});
	
	//Click 'contact us':
	$('.contact_us').click( function(){	show_greyout(); $('#popup_contact_form').show("slow"); return false;	});
	
	//Click 'location':
	//$('#location a').click( function(){	show_greyout(); $('#popup_location').show("slow"); return false;	});
	
	//Close popups
	$('#greyout, #x, #x2, #x3').click( function(){	hide_greyout(); $('#popup_contact_form, #popup_form, #popup_location').hide("slow"); GMap2.checkResize(); return false;	});
	
	//Click send in 'contact us'
	$('#submit-contact').click( function(){
		if (	$("#contact_form").valid()	){
			$.post("php/send_mail.php", $("#contact_form").serialize());
			Link('#popup_contact_form', 'thanks.php');
			return false;
		}
		else {
			//alert ('invalid');
		}
	});
	
	//Click send in 'get a quote'
	$('#submit-quote').click( function(){
		if (	$("#product_form").valid()	){
			$.post("php/send_quote.php", $("#product_form").serialize());
			Link('#popup_form', 'thanks.php');
			return false;
		}
		else {
			//alert ('invalid');
		}
	});
	
  //Form validation (Get a Quote)
	$("#product_form").validate();
	
	//Form validation (Contact us)
	$("#contact_form").validate();
	
	

	
});