jQuery(document).ready( function() {
	/*cufon*/
	Cufon.replace('.vid-intro, #right-side h1');
	/*video*/
	$('.media').media({ 
		width:     471, 
		height:    357,
		flashvars: {
			autostart:true,
			showdigits:false,
			showicons:false,
			shownavigation:false,
			controlbar:'over'
		},
		caption:   false
	});
	/*slideshow*/
	$(".scrollable").scrollable();
	$('.img img').mouseenter(function(){
		$('.popup').hide();
		var offset = $(this).offset();
		var iclass = $(this).attr("class");
		$('.pop-'+iclass).css('left',offset.left-32);
		$('.pop-'+iclass).show();
	}).mouseleave(function(){
		var iclass = $(this).attr("class");
		$('.pop-'+iclass).hide();	
	}); 
	/*left blocs*/
	$('.orange-body, .orange-footer').hide();
	$('.body-newsletter, .footer-newsletter').show();
	$('.distributor span').click(function(){
		$('.body-newsletter').slideUp('slow',function(){ $('.footer-newsletter').hide(); });
		$('.footer-login').show();
		$('.body-login').slideDown('slow');	
	}); 
	$('.newsletter span').click(function(){
		$('.body-login').slideUp('slow',function(){ $('.footer-login').hide(); });
		$('.footer-newsletter').show();
		$('.body-newsletter').slideDown('slow');		
	});
	/*drop down*/
	$("#main-menu li").mouseenter(function() {  
		$(this).find("ul").fadeIn();
	}).mouseleave(function(){
      $(this).parent().find("ul").fadeOut();
    });
	/*forms*/
	$('.quote').click(function(){		
		var tmpURL = window.location.toString().split('?');
		window.location=tmpURL[0]+"?form=quote";
		//$('#quote_form').modal({appendTo:'form'});
	});	
	$('.contact').click(function(){	
		var tmpURL = window.location.toString().split('?');
		window.location=tmpURL[0]+"?form=contact";	
		//$('#contact_form').modal({appendTo:'form'});
	});	
	if(getQuerystring('form') == "quote"){
		$('#quote_form').modal({appendTo:'form'});
	} else if(getQuerystring('form') == "contact"){
		$('#contact_form').modal({appendTo:'form'});
	}
	$('.close').click(function(){
		$.modal.close();
		$("#prod_desc_popup").show();	
	});
	/*prod desc*/
	$('#prod-img img, #prod-img a').click(function(){
		$("#prod_desc_popup").show();	
	}); 
	$('.close, #prod_desc_popup a').click(function(){
		$.modal.close();
		$("#prod_desc_popup").hide();	
	});	
	/*tabs*/
	$("ul.tabs").tabs("div.panes > div");	
	/*gallery*/
	$('.client-thumbnail img').css("margin-top",($('.client-thumbnail').height()-$('.client-thumbnail img').height()-60)/2);
	$('.client-thumbnail img').mouseenter(function(){
		var imgsrc = $(this).attr('src');
		imgsrc = imgsrc.replace("/logos/desat/","/logos/");
		$(this).attr('src',imgsrc);
	}).mouseleave(function(){
		var imgsrc = $(this).attr('src');
		imgsrc = imgsrc.replace("/logos/","/logos/desat/");
		$(this).attr('src',imgsrc);	
	});	
});	

function getQuerystring(key, default_)
{
  if (default_==null) default_="";
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
}
