
//we have to know if the user agent is IE6 or not (png or whatever)
var badBrowser = (/MSIE ((5\.5)|6|7)/.test(navigator.userAgent) && navigator.platform == "Win32");

////////////////////////////////////////////////////////some functions

/** Ouverture d'une nouvelle fen?tre en 1024 * 768 */
function popupBigWindow( link )
{
	window.open( link, '', 'width=1024, height=768, resizable=yes' );
}

function OpenPopUp(MyFile,MyWindow,MyWidth,MyHeight)
//MyFile :   nom du fichier contenant le code HTML du pop-up 
//MyWindow :   nom de la fenêtre (ne pas mettre d'espace) 
//MyWidth :   entier indiquant la largeur de la fenêtre en pixels 
//MyHeight :   entier indiquant la hauteur de la fenêtre en pixels 

{    
var ns4 = (document.layers)? true:false;    //NS 4 
var ie4 = (document.all)? true:false;   //IE 4 
var dom = (document.getElementById)? true:false;   //DOM 
var xMax, yMax, xOffset, yOffset;;    

    if (ie4 || dom)
        {
        xMax = screen.width;
        yMax = screen.height;
        }
    else if (ns4)
        {
        xMax = window.outerWidth;
        yMax = window.outerHeight;
        }
    else
        {
        xMax = 800;
        yMax = 600;
        }
    xOffset = (xMax - MyWidth)/2;
    yOffset = (yMax - MyHeight)/2;
    window.open(MyFile,MyWindow,'width='+MyWidth
+',height='+MyHeight
+',screenX='+xOffset
+',screenY='+yOffset
+',top='+yOffset
+',left='+xOffset
+',scrollbars=no,resizable=no');
}

function submitPayment(orderId)
{
	if (document.getElementById('paypal').checked)
		document.PaymentRequest.submit();
	else if (document.getElementById('cb').checked)
		document.PaymentRequest.submit();
	else if (document.getElementById('paper').checked)
		window.location.href='payOrder.action?order.id='+orderId+'&paymentTypeId=2';
	else if (document.getElementById('phone').checked)
		window.location.href='payOrder.action?order.id='+orderId+'&paymentTypeId=3';
	else
		alert('Veuillez sélectionner un mode de paiement.');
}

function checkConditions()
{
	if (!jQuery("#conditions").is(':checked'))
	{
		alert('Veuillez accepter les conditions générales de vente');
		return false;
	}
	window.location.href='step1Order.action';
}

function checkConditionsValidate()
{
	if (!jQuery("#conditions").is(':checked'))
	{
		alert('Veuillez accepter les conditions générales de vente');
		return false;
	}
	window.location.href='createOrder.action';
}

function changeCountry(id)
{
	var element  = document.getElementById(id);
	document.location.href='/changeCountryBasket.action?country.id='+element.value;
}

function showHideBlock(blockId)
{
	if (jQuery("#"+blockId).is(":hidden"))
	{
		jQuery("#"+blockId).show();
	}
	else
	{
		jQuery("#"+blockId).hide();
	}
}


function sameAddressShowHide()
{
	if (jQuery("#deliveryAddr").is(":hidden"))
	{
		jQuery("#deliveryAddr").show();
	}
	else
	{
		jQuery("#deliveryAddr").hide();
	}
}

function showHideCodePromo()
{
	if (jQuery("#formCodePromo").is(":hidden"))
	{
		jQuery("#formCodePromo").show();
	}
	else
	{
		jQuery("#formCodePromo").hide();
	}
}

function getElementsByClass(searchClass,node,tag) {
   
   	//elementsbyclassname exist in ff3 :)
	if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent))
	{
		var ffversion=new Number(RegExp.$1) // capture x.x portion and store as a number
		if (ffversion>=3)//ok with ff3
		{
			return document.getElementsByClassName(searchClass);
		}
	}
		
		var classElements = new Array();
        if ( node == null )
                node = document;
        if ( tag == null )
                tag = '*';
        var els = node.getElementsByTagName(tag);
        var elsLen = els.length;
        var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
        for (i = 0, j = 0; i < elsLen; i++) {
                if ( pattern.test(els[i].className) ) {
                        classElements[j] = els[i];
                        j++;
                }
        }
        return classElements;
}


function create_flash_player(id_div, file, javascriptid, click_link, autostart,width,height,volume,usefullscreen)
{
	if(usefullscreen==undefined)
	{
		usefullscreen = 'false';
	}

	var player_instance = new SWFObject('flash/mediaplayer/mediaplayer.swf',javascriptid,width,height,'9,0,115,0');
	player_instance.useExpressInstall('flash/express_installation/playerProductInstall.swf');
	player_instance.addParam('allowscriptaccess','always');
	player_instance.addParam('allowfullscreen',usefullscreen);
	player_instance.addVariable('wmode','transparent');
	player_instance.addVariable('width',width);
	player_instance.addVariable('height',height);
		
	//Have to test if there is already a parameter in the url, if yes I have to encode teh second one (strnage...)
	if(file.indexOf('?')!=-1)
	player_instance.addVariable('file',escape(file)+escape("&ext=.flv"));
	else
	player_instance.addVariable('file',escape(file)+"&ext=.flv");
	
	player_instance.addVariable('bufferlength','5');
	player_instance.addVariable('javascriptid',javascriptid);
	player_instance.addVariable('enablejs','true');
	player_instance.addVariable('usefullscreen',usefullscreen);
	player_instance.addVariable('autostart',autostart);
	player_instance.addVariable('volume',volume);
	
	if(click_link!='')
	{
		player_instance.addVariable('linkfromdisplay','true');
		player_instance.addVariable('link',click_link);
		player_instance.addVariable('linktarget','_self');
	 }
	 
	player_instance.write(id_div);
 };
 
function create_wmv_player(id_div, file, javascriptid, autostart,width,height,volume,usefullscreen)
{
	if(usefullscreen==undefined)
	{
		usefullscreen = 'false';
	}
	
	//don't ask me why but jQuery html() doesn't work in this function....in IE7....
	document.getElementById(id_div).innerHTML=('<object type="video/x-ms-wmv" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" data="'+file+'" id="'+javascriptid+'" width="'+width+'" height="'+height+'"><param name="url" value="'+file+'" /><param name="autostart" value="'+autostart+'" /><param name="volume" value="'+volume+'" /><param name="controller" value="true" /><param name="uiMode" value="full" /><param name="stretchToFit" value="true" /><embed type="video/x-ms-asf-plugin" pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/" src="'+file+'" name="'+javascriptid+'" id="'+javascriptid+'" autostart="'+autostart+'" showcontrols="1" animationatstart="0" transparentatstart="1" AllowChangeDisplaySize="1" enableContextMenu="1" width="'+width+'" height="'+height+'" ShowStatusBar="1" uiMode="full"></embed></object>');

};

function create_realvideo_player(id_div, file, javascriptid, autostart,width,height,volume,usefullscreen)
{
	if(usefullscreen==undefined)
	{
		usefullscreen = 'false';
	}
	
	document.getElementById(id_div).innerHTML=('<embed name="clip" type="audio/x-pn-realaudio-plugin" src="'+file+'" width="'+width+'" height="'+height+'" nojava="true" backgroundcolor="black" controls="ImageWindow" console="one" nologo="true" autostart="'+autostart+'" center="false" maintainaspectratio="true"/><embed class="real_control" name="controls" type="audio/x-pn-realaudio-plugin" height="20" style="width:66%" controls="ControlPanel" console="one"/><embed class="real_control"  name="status"type="audio/x-pn-realaudio-plugin" height="20" style="width:33%;_width:100%;!width:100%" controls="PositionField" console="one"/>');

};

///////////////////////////////////
//jwplayer javascript control
function sendEvent(swf,typ,prm) { 
  thisMovie(swf).sendEvent(typ,prm); 
};

function thisMovie(swf) {
  if(navigator.appName.indexOf("Microsoft") != -1) {
    return window[swf];
  } else {
    return document[swf];
  }
};

function loadFile(swf,obj,type) {

if(document.getElementById(swf) && obj!=undefined)
{
	//the height should be increased, because we have to count the control height...
	if(type==undefined || type=='mp3' || type=='flv')//default case --> flash player
	create_flash_player(swf, obj.file, obj.javascriptid, obj.click_link, obj.autostart,obj.width,(parseInt(obj.height)+20),obj.volume,obj.usefullscreen);
	else if(type=='wmv' || type=='wma')
	create_wmv_player(swf, obj.file, obj.javascriptid, obj.autostart, obj.width,(parseInt(obj.height)+64),obj.volume,obj.usefullscreen);
	else if(type=='real')
	create_realvideo_player(swf, obj.file, obj.javascriptid, obj.autostart, obj.width,(parseInt(obj.height)),obj.volume,obj.usefullscreen);
	};
}


function hide_video() {
jQuery('#main_video').css({ visibility:"hidden"});
}
function show_video() {
jQuery('#main_video').css({ visibility:"visible"});
}

function previousImage()
{
	var currentPosition = jQuery("#currentPhotoOrdre").attr("value");
	if (currentPosition > 0)
	{
		currentPosition--;
		jQuery("#currentPhotoOrdre").val( currentPosition );
		jQuery("#image").attr("src", jQuery("#gallery"+currentPosition).attr("value"));
		underlineImageLink(currentPosition);
	}
}

function nextImage()
{
	var currentPosition = jQuery("#currentPhotoOrdre").attr("value");
	var nbImage = jQuery("#nbPhotos").attr("value");
	if (currentPosition < nbImage - 1)
	{
		currentPosition++;
		jQuery("#currentPhotoOrdre").val( currentPosition );
		jQuery("#image").attr("src", jQuery("#gallery"+currentPosition).attr("value"));
		underlineImageLink(currentPosition);
	}
}

function updateNavigationButtons(index)
{
	var currentPosition = index;
	jQuery("#currentPhotoOrdre").val( currentPosition );
	jQuery("#image").attr("src", jQuery("#gallery"+currentPosition).attr("value"));
	underlineImageLink(index);
}
function underlineImageLink(index){

	var nbImage = jQuery("#nbPhotos").attr("value");
	for(i = 0; i< nbImage; i++){
	 if(i == index){
		jQuery("#photoLink"+i).attr("class", "");	 
	 }else{
		jQuery("#photoLink"+i).attr("class", "selected");	 
	 }
	}

}

jQuery(document).ready(function(){

//bind focus on input field
jQuery('#keyword').bind("focus", function(event,data){
this.value = '';
return false
});

jQuery('#email').bind("focus", function(event,data){
this.value = '';
return false
});

$(".rollover").hover(
	function(){
		if($(this).attr("src").indexOf("_on") == -1) {
			var newSrc = $(this).attr("src").replace("_off.png","_on.png#hover");
			$(this).attr("src",newSrc);
		}
	},
	function(){
		if($(this).attr("src").indexOf("_on.png#hover") != -1) {
			var oldSrc = $(this).attr("src").replace("_on.png#hover","_off.png");
			$(this).attr("src",oldSrc);
		}
	}
);
});