
//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


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"});
//}

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
});

jQuery('#mailAbonnement').bind("focus", function(event,data){
this.value = '';
return false
});

jQuery('.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);
		}
	}
);

});

function subscribeAlert()
{
	var mail = jQuery('#mailAbonnement').serialize();;
	var ficheId = jQuery('#identifiantFiche').serialize();;
	var dataForm = mail + "&" + ficheId;
	
	jQuery.ajax({
	   type: "POST",
	   url: "abonnementFiche.html",
	   data: dataForm,
	   success: function(msg){
		   if(msg.indexOf('fiche.abonnement.error') == -1){
			   jQuery('#abonnement').hide('fast');
		   }
			   jQuery('#abonnementok').html(msg);
			   jQuery('#abonnementok').show('fast');
	   }
 	});
}
