// JavaScript Document

var oldMsg;
var radio = false;
var timer;


function mainloader(){
	var d = new Date();
	window.name = d.getTime();
	ucfw4(); 
	
	var version = getFlashVersion().split(','); 
	if(version[0] < 10 && (version[0]<9 || (version[0]==9 && (version[1]<0 || (version[1]==0 && version[2]<124)))))
		$('#errorsconfig').html('<br /><br /><strong class="red center" style="border: 1px solid red;"><br /><br />VOUS NE DISPOSEZ PAS DE LA VERSION LA PLUS RECENTE DE FLASH PLAYER (Votre version: '+version.join('.')+')<br /> CE SITE WEB EST OPTIMISE POUR UNE VERSION PLUS RECENTE (Version minimum: 9.0.124)<br /><br />Vous pouvez télécharger et installer la version la plus récente dès maintenant pour visualiser ce site Web dans sa version complète, cette opération ne prendra que quelques instants.<br /><br />Pour mettre à jour FLASH PLAYER rendez-vous <a target="_blank" href="http://www.macromedia.com/go/getflashplayer">ici</a><br /><br /></strong><br /><br />'); 
	
	$("a[rel*=modal]").facebox(null, false);

	setYouTubesMenu();
	setLoggedMsgs();
	setPlayerFlashPromo();
	setTimeLeft();
	voteGagnant();
	setRadio();
	
	
	var posMessage = strpos(document.location.href, '#msg');
	if(posMessage!==false){
		var session = document.location.href.substring((posMessage+5), document.location.href.length);
		$(this).facebox(null, "/Account/noaction_"+session+"/");
		if (!$.browser.msie)
			document.location.replace('#');
			
	}

}

function setRadio(){
	$('a.radio').hover(function(){
		$(this).css({'right':'-4px'});							
	}, function(){
		$(this).animate({'right':'-8px'});							
	});
	$('a.radio').click(function(){
		if (!radio || radio.closed){
			var l = 510; var h = 400; var top = (screen.height-h)/2; var left = (screen.width-l)/2;
			radio = window.open($(this).attr('href')+'layout_0/', 'RADIO', 'width='+l+', height='+h+', top='+top+', left='+left+', scrollbars=no, resizable=no, toolbar=no, menubar=no, location=no, status=no');
		}
		radio.window.focus();
		return false;
	});	
}

function setTimeLeft(){
	var timeTab = $('#time strong').html().split(':');
	if(!timeTab)
		return;
	if(timeTab[2]==0) {
		if(timeTab[1]==0) {
			if(timeTab[0]==0) {
				clearInterval(timer);
				document.location.reload();
				return false;
			}
			else {
				--timeTab[0];
				if(timeTab[0]<10)
					timeTab[0] = '0' + timeTab[0];
				timeTab[1] = timeTab[2] = 59;
			}
		}
		else {
			--timeTab[1];
			if(timeTab[1]<10)
				timeTab[1] = '0' + timeTab[1];
			timeTab[2] = 59;
		}
	}
	else { 
		--timeTab[2];
		if(timeTab[2]<10)
			timeTab[2] = '0' + timeTab[2];
	}
	$('#time strong').html(timeTab.join(':'));
	setTimeout(function() { setTimeLeft() }, 1000); 
}


function voteGagnant(){
	$('a[rel=avis]').click(function(){
		var consernedGagnantVote = $(this);
		$.ajax({
			url: $(this).attr('href'),
			type: 'POST',
			contentType: "application/x-www-form-urlencoded;charset=iso-8859-1",
			
			success: function(data){
				consernedGagnantVote.parent().html(data);
			}
		});
		return false;
	});
}

function strpos (haystack, needle, offset) {
    var i = (haystack+'').indexOf(needle, (offset ? offset : 0));
    return i === -1 ? false : i;
}


function getPresentationArtistes(){
	if (($.browser.msie && $.browser.version.substr(0,1)<7) && (window.location.href == 'http://www.castarprod.com' || window.location.href == 'http://www.castarprod.com/' || window.location.href == 'http://castarprod.com' || window.location.href == 'http://castarprod.com/'))
		location.replace('/#msg_errornav');
	$.ajax({
		url: '/Webservice/layout_0/',
		type: 'POST',
		contentType: "application/x-www-form-urlencoded;charset=iso-8859-1",
		
		success: function(data){
			$('#presentationArtistes').html(data);
			setTimeout(preloadImage); 
			setFullPlayers(false, '.fullPlayer', true);
			if ($.browser.msie && $.browser.version.substr(0,1)<8){
				$('#backgroundAnnim').css({'display':'none'});
				$('div.content div#presentationArtistes').css({'background':'#FFF'});
				$('div.content div#presentationArtistes').css({'background':'#FFF'});
			}
			$('#presentationArtistes').castarprod();
		}
	});

}

function addZero(chiffre){
	if (chiffre < 10) { chiffre = "0"+chiffre; }
	if (chiffre < 100) { chiffre = "0"+chiffre; }
	return chiffre; 

}


var loadingAnnim=0;

function preloadImage(){ 
	var myContent;
	$("#presentationArtistes").each(function(){
		myContent = this.getElementsByTagName("img");
	});
	var totalImage = myContent.length;
	percent = Math.ceil((loadingAnnim+1)*100/totalImage);
	if (loadingAnnim < totalImage){
		if (myContent.item(loadingAnnim).complete) {  
			$("#preloadPercent").html(percent-1); 
			++loadingAnnim;
		}
		setTimeout(preloadImage); 
	}
	else {  
		$("#preloadPercent").html('100'); 
		$("#chargementAnnim").fadeOut();
		$.castarprod.changeTo($('#miniature3'));
		$.castarprod.changeTo($('#miniature0'));
		ucfw4_annim();
		//
	}

}


function setLoggedMsgs(){
	$('ul.logged a').mouseover(function(){ oldMsg=$('#descriptor').text(); $('#descriptor').text($(this).attr('title')); });
	$('ul.logged a').mouseout(function(){ $('#descriptor').text(oldMsg); });
	

}


function getFlashVersion(){ 
  // ie 
  try { 
    try { 
      var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6'); 
      try { axo.AllowScriptAccess = 'always'; } 
      catch(e) { return '6,0,0'; } 
    } catch(e) {} 
    return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
  } catch(e) { 
    try { 
      if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin)
        return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1]; 
    } catch(e) {} 
  } 
  return '0,0,0'; 
} 

function getFirstWord(textname, classname){
	var arrTxt = textname.split(' ');
	if(classname=='two')
		return arrTxt[0]+' '+arrTxt[1];
	else
		return arrTxt[0];
}