//======================================================================//
//== About rough.js
//==--------------------------------------------------------------------//
//== This file is part of rough project.
//== Copyright (c) 2009-2010 - Erwan LE LOSTEC
//== Licensed under the GPL version 2.0 license.
//== See LICENSE file or
//== http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
//==--------------------------------------------------------------------//
//== Contributor : Erwan LE LOSTEC
//== Contributor : Clement DEGANDT
//==--------------------------------------------------------------------//

//--fonctions appelees par le flash
function swf_suivant()
{
	$.post("ajax/souscategories.php" , { action: "get_next_ads", cat_key: cat_key, num_ads: num_ads } , function(data) { $("#teaserAds").html(data); return false; });
}
function stocke_informations(infos)
{
	//
}
function setinfos()
{
	//
}
//==--------------------------------------------------------------------//
function externalLinks() 
{/** @function externalLinks()
  * make compatible target attribute for HTML 4.0 specification
  *
  * @return	<boolean>
  **/ 
	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 = function () 
{
	externalLinks();
	$(function() 
	{
		$('#login').hover(function() 	{ $(this).animate({top:'5px'}, { queue:false, duration:500 }); }
						, function() 	{ $(this).animate({top:'0px'}, { queue:false, duration:500 }); });
		$('#basket').hover(function()	{ $(this).animate({top:'5px'}, { queue:false, duration:500 }); }
						 , function()	{ $(this).animate({top:'0px'}, { queue:false, duration:500 }); });
		//-- gestion url connexion deconnexion
		if($('#login')) { $('#form_logout').attr('action', $(location).attr('href')); };
	});
	/////////////// gestion alerte de confirmation de connexion ///////////////
	if($('#messageCreateLogin').length > 0) 
	{
		$('#maqbox').unbind();
		var tmp 						= $('#messageCreateLogin').attr('class').split('_');
		var txt 						= $('#messageCreateLogin').html();
		var textClose 					= tmp[1];
		var load_image					= $('#css_path').val() + "images/maqbox/loading.gif";
		var close_image					= $('#css_path').val() + "images/maqbox/closelabel.gif";
		$.maqbox.settings.loading_image	= load_image;
		$.maqbox.settings.close_image	= close_image;
		$.maqbox.settings.close_text	= textClose;
		jQuery.maqbox(txt);
	}
	////////////////// slider menu du haut //////////////////
	$('#slider_scroll').slider({
		min		: 0,
    	max		: $('#slide').innerWidth(),
    	stop	: function (event, ui) 
        {
        	$('#val').val('stop');
        	$('#slide > ul').animate( {'left' : -ui.value * ((parseFloat($('#slide > ul').innerWidth()) - parseFloat($('#slide').innerWidth())) / parseFloat($('#slide').innerWidth())) }, 500);
        },
		slide: function (event, ui)
		{
			$('#slide > ul').css('left', -ui.value * ((parseFloat($('#slide > ul').innerWidth()) - parseFloat($('#slide').innerWidth())) / parseFloat($('#slide').innerWidth())));
        }
    });
	///////////////////// rectification IE7-6 //////////////////////////
	if (navigator.appName == "Microsoft Internet Explorer" && (navigator.appVersion.substr(22,1) == "6" || navigator.appVersion.substr(22,1) == "7" )&& $('#slide ul').length > 0) 
	{
		var nbVignette 		= $('#slide ul li').length;
		var largeur 		= ($('#slide ul li:first').width()) + (2 * parseInt($('#slide ul li:first').css('margin-right').substr(0,2)));
		var total 			= largeur * nbVignette + nbVignette * 2 ;
		$('#slide ul').width(''+ total +'px');
	}
	///////////////////// rectification IE7-6 //////////////////////////
	if (navigator.appName == "Microsoft Internet Explorer" && (navigator.appVersion.substr(22,1) == "6" || navigator.appVersion.substr(22,1) == "7") && $('.bloc').length > 0) 
	{
		if($("#categories_menu").height() > $("#teaserAds").height()) 
		{
			var marge 		= (($("#categories_menu").height() - ($("#teaserAds").height() )) + parseInt($('#help').css('margin-top').substr(0,2))  )  ;
			$('#teaserAds').css('margin-bottom',''+(marge - 2)+'px');
		} 
		else  				{ $('#teaserAds').after('<div class="spacer"></div>'); }
	}
	///////////////////// rectification IE7-6 //////////////////////////
	if (navigator.appName == "Microsoft Internet Explorer" && (navigator.appVersion.substr(22,1) == "6" || navigator.appVersion.substr(22,1) == "7")) 
	{
		if($("#categories_menu").height() < $("#main").height()) {
			if($('.bloc').length > 1)
			{
				var marge 	= $("#main").height() - $("#categories_menu").height();
				if(navigator.appVersion.substr(22,1) == "7") 	{ $("#categories_menu").css('margin-bottom',''+(marge+5)+'px'); }
				else 											{ $("#categories_menu").css('margin-bottom',''+(marge - 8)+'px'); }
			}
			else 			{ $("#categories_menu").css('margin-bottom','5px'); }
		} 
		else 
		{
			$("#categories_menu").css('margin-bottom','5px');
			$("#main").css('margin-bottom','15px');
		}
		$('.adresse_view .bouton').css('margin-top','0px');
	}
	///////////////////// rectification IE6 //////////////////////////
	if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.substr(22,1) == "6")
	{
		$(".menu_shadows").remove();
		$(".shadows").remove();
		$("#main .content, #basket_main .content, #main .contentpage").remove();
		$("#sub_categories_products >  ul > li > div.products_picto > img.prod_icon").each(
			function() 
			{
				var str 		= $(this).attr('src');
				var newstr 		= str.replace(/png/gi, 'gif');
				$(this).attr('src',newstr);
			}
		);
		$('#categories_menu > #menu > li:not(".selected")').hover(
			function() { $(this).css('font-weight','bold'); $(this).css('background-position','0 0'); },
			function() { $(this).css('font-weight','normal'); $(this).css('background-position','0 -40px'); }
		);
		$('.liens_index').hover(
			function() { $(this).css('color','#FFFFFF'); },
			function() { $(this).css('color',''); }
		);
	}
	/////////////// pour les categories /////////////////////////////
	if($('#categories_choice').length > 0)
	{
		$('[id^="sub_cat_txt_"]').each(
			function()
			{
				var tmp 		= $(this).attr('id').split('_');
				var num_cat 	= tmp[3];
				var marge 		= 680 - ($('#sub_cat_img_'+ num_cat +'').width());
				if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.substr(22,1) == "6")
				{
					$('#sub_cat_txt_'+ num_cat +' > .sub_categories_details > .details_').css('width',''+ marge +'');
					$('#sub_cat_txt_'+ num_cat +'').css('margin-left',''+ ($('#sub_cat_img_'+ num_cat +'').width() - ($('#sub_cat_img_'+num_cat+'').width() / 2) + 10)+'px');
					$('#sub_cat_txt_'+ num_cat +'').css('margin-top','-'+ $('#sub_cat_img_'+ num_cat +'').height() +'px');
				}
			}		   
		);
	}
	/////////////// pour la deconnexion du user /////////////////////////////
	$('.login_off').click(
		function () {		
			$('#maqbox').unbind();
			var textClose 					= 'Annuler';
			var message 					= $('#message_logout').html();
			$.maqbox.settings.close_text	= textClose;
			var load_image					= $('#css_path').val() + "images/maqbox/loading.gif";
			var close_image					= $('#css_path').val() + "images/maqbox/closelabel.gif";
			$.maqbox.settings.loading_image	= load_image;
			$.maqbox.settings.close_image	= close_image;
			jQuery.maqbox(message);
			if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.substr(22,1) == "8")
			{
			   $('#maqbox #form_logout').attr('action' , $('#maqbox #form_logout').attr('action') + '/');
			}
			$('#maqbox #login_off_button').live( "click" , function () { $('#maqbox #form_logout').submit(); } );
		}
	);
	/////////////// fil arianne gestion des h1 et h2 title /////////////////////////////
	if($('#breadcrumb').length > 0) 
	{
		var direction1 						= $('h1:[title!=""]').attr('title');
		var direction2 						= $('h2:[title!=""]').attr('title');
		$('#breadcrumb h1:[title!=""]').hover(
			function() { $(this).attr('title',''); },
			function() { $(this).attr('title',direction1); }
		);
		$('#breadcrumb h2:[title!=""]').hover(
			function() { $(this).attr('title',''); },
			function() { $(this).attr('title',direction2); }
		);
		$('#breadcrumb h1:[title!=""]').click( function() { window.location = direction1; } );
		$('#breadcrumb h2:[title!=""]').click( function() { window.location = direction2; } );
	}
	/////////////// apparence ///////////////
	if($('.bloc').length == 1 && (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.substr(22,1) == "6")) 	{ $('.bloc').css('margin-left','7px').css('float','right'); }
	if($("#main").height() > $("#categories_menu").height()) 																		{ $("#main").next('.spacer').remove(); }
};
