function getMiddleHeight(valHeight)
{
	var $bodyHeight = $('body').height();
	$('#content').css('min-height', $bodyHeight-valHeight);
}

(function($)
{
	$(document).ready(function() {
		//style switching function
		$('.styleswitch').click(function()
		{
			switchStylestyle("styles_pattern"+this.getAttribute("rel"));
			return false;
		});
		var c = readCookie('style');
		if (c) switchStylestyle(c);
	});

	function switchStylestyle(styleName)
	{
		$('link[@rel*=style][title]').each(function(i) 
		{
			this.disabled = true;
			if (this.getAttribute('title') == styleName) this.disabled = false;
		});
		createCookie('style', styleName, 365);
	}
})(jQuery);

function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name)
{
	createCookie(name,"",-1);
}


$(document).ready(function() {
	
	if($page != 'accueil')
	{
		getMiddleHeight(360);
	}
	$(window).resize(function() {
		if($page != 'accueil')
		{
			getMiddleHeight(360);
		}	
	});

	

	$("#accueil DIV A").mouseover(function(){
		$("#accueil").removeClass();
		$("#accueil").addClass('onglet1-actif');
	});
	
	$("#accueil DIV A").mouseout(function(){
		
		$("#accueil").removeClass();
		$("#accueil").addClass('onglet1-inactif');
	});
	
	
	$("#produits").mouseover(function(){
		$("#produits").removeClass();
		$("#produits").addClass('onglet4-actif');
	});

	
	if($page && $page!='produits')
	{
		$("#produits").mouseout(function(){
		
			$("#produits").removeClass();
			$("#produits").addClass('onglet4-inactif');
		});
	}
	
	$("#services").mouseover(function(){
		$("#services").removeClass();
		$("#services").addClass('onglet2-actif');
	});
	
	if($page!='services')
	{
		$("#services ").mouseout(function(){
		
			$("#services").removeClass();
			$("#services").addClass('onglet2-inactif');
		});
	}
	
	$("#contacts DIV A").mouseover(function(){
		$("#contacts").removeClass();
		$("#contacts").addClass('onglet2-actif');
	});
	
	$("#contacts DIV A").mouseout(function(){
		
		$("#contacts").removeClass();
		$("#contacts").addClass('onglet2-inactif');
	});
	
	
	
	$('#origStyle').click(function(){
		$('#stylesheets').attr('href','css/styles_patternStandard.css');
		document.cookie="style=styles_patternStandard";
	});
	
	$('#greenStyle').click(function(){
		$('#stylesheets').attr('href','css/styles_patternGreen.css');
		document.cookie="style=styles_patternGreen";
	});
	
	$('#classicStyle').click(function(){
		$('#stylesheets').attr('href','css/styles_patternClassic.css');
		document.cookie="style=styles_patternClassic";
	});
	
	
	
	// Expand Panel - Sliding panels
	$("#open").click(function(){
		$("div#panel").animate({ 
        width: "196"
      }, 1000 );
		$("#formLogin").show('slow');
		
	});	
	
	// Collapse Panel
	$("#close").click(function(){
		$("div#panel").animate({ 
        width: "35"
      }, 1000 );
		$("#formLogin").hide('slow');
	});		
	
	// Switch buttons from "Log In | Register" to "Close Panel" on click
	$("#open").click(function () {
		//$(".toggleLogin").toggle();
	});	
	
	jQuery.each(jQuery.browser, function(i, val) {
	  if(i=="msie" && jQuery.browser.version.substr(0,1) == "7")
	  {		 
		 $('#CssSwitch').css('margin-top','0');
	  }
		 
	});
	
	// Expand Panel cssSwitch
	$("#openCssSwitch").click(function(){
		$("div#panelCssSwitch").animate({ 
        width: "196"
      }, 1000 );
	});	
	
	// Collapse Panel
	$("#closeCssSwitch").click(function(){
		$("div#panelCssSwitch").animate({ 
        width: "35"
      }, 1000 );
	});		
	
	// Switch buttons from "Log In | Register" to "Close Panel" on click
	$("#openCssSwitch").click(function () {
		//$(".toggleLogin").toggle();
	});	
	

	//menu d�roulant :: style un sur deux
	$("ul.menu_body li:even").addClass("alt");
   	$("ul.menu_bodyProd li:even").addClass("alt");
	
		
		$('#services').mouseover(function () {
			$('#services').height('auto');
			$('#carousel').css('z-index', -100);
			
    	});
		$('#services').mouseout(function () {
			$('#services').height('37px');
			$('#carousel').css('z-index', 1000);
			
    	});
		
		    
		$('ul.menu_body li a').mouseover(function () {
    	    $(this).animate({paddingLeft: "15px" }, 50 );
    	});
    
		$('ul.menu_body li a').mouseout(function () {
    	    $(this).animate({paddingLeft: "10px" }, 50 );
    	});
		
		
		//menu d�roulant Bis
		$('#produits').mouseover(function () {
			$('#produits').height('auto');			
			$('#carousel').css('z-index', -100);
    	})

   		$('#produits').mouseout(function () {
			$('#produits').height('37px');
			$('#carousel').css('z-index', 1000);
			
    	});
		
		$('ul.menu_bodyProd li a').mouseover(function () {
    	    $(this).animate({paddingLeft: "15px" }, 50 );
    	});
    
		$('ul.menu_bodyProd li a').mouseout(function () {
    	    $(this).animate({paddingLeft: "10px" }, 50 );
    	});



// Create a jquery plugin that prints the given element.
jQuery.fn.print = function(){
	// NOTE: We are trimming the jQuery collection down to the
	// first element in the collection.
	if (this.size() > 1){
		this.eq( 0 ).print();
		return;
	} else if (!this.size()){
		return;
	}
 
	// ASSERT: At this point, we know that the current jQuery
	// collection (as defined by THIS), contains only one
	// printable element.
 
	// Create a random name for the print frame.
	var strFrameName = ("printer-" + (new Date()).getTime());
 
	// Create an iFrame with the new name.
	var jFrame = $( "<iframe name='" + strFrameName + "'>" );
 
	// Hide the frame (sort of) and attach to the body.
	jFrame
		.css( "width", "1px" )
		.css( "height", "1px" )
		.css( "position", "absolute" )
		.css( "left", "-9999px" )
		.appendTo( $( "body:first" ) )
	;
 
	// Get a FRAMES reference to the new frame.
	var objFrame = window.frames[ strFrameName ];
 
	// Get a reference to the DOM in the new frame.
	var objDoc = objFrame.document;
 
	// Grab all the style tags and copy to the new
	// document so that we capture look and feel of
	// the current document.
 
	// Create a temp document DIV to hold the style tags.
	// This is the only way I could find to get the style
	// tags into IE.
	var jStyleDiv = $( "<div>" ).append(
		$( "style" ).clone()
		);
 
	// Write the HTML for the document. In this, we will
	// write out the HTML of the current element.
	objDoc.open();
	objDoc.write( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" );
	objDoc.write( "<html>" );
	objDoc.write( "<body>" );
	objDoc.write( "<head>" );
	objDoc.write( "<title>" );
	objDoc.write( document.title );
	objDoc.write( "</title>" );
	objDoc.write( jStyleDiv.html() );
	objDoc.write( "</head>" );
	objDoc.write( this.html() );
	objDoc.write( "</body>" );
	objDoc.write( "</html>" );
	objDoc.close();
 
	// Print the document.
	objFrame.focus();
	objFrame.print();
 
	// Have the frame remove itself in about a minute so that
	// we don't build up too many of these frames.
	setTimeout(
		function(){
			jFrame.remove();
		},
		(60 * 1000)
		);
}


	// print function
	$('#cta2').click( function () {
			$('#ctaProd').hide();					   
			$('#content').print();
			$('#ctaProd').show();		

	});
	
});

// JavaScript Document
