$(document).ready(function(){
	add_search_action();
	
	if(typeof sIFR == "function"){
	    sIFR();
	};
	if(typeof sIFR == "function"){
    	sIFR.replaceElement("div#sec-content h3", named({sFlashSrc: "/public/sifr/futuraheavy.swf", sColor: "#ffffff", sCase: "upper", sBgColor: "#000000", sWmode:"transparent", sLinkColor: "#ffffff"}));
	}
	
	
	//les liens de scroll
	if ($('a.scroll').length) {
	  $('a.scroll').click(function() {
		  var $target = $(this.hash);
		  $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
		  $('html,body').animate({ scrollTop: $target.offset().top }, 1000);
		  return false;
	  })
	}
	
	
	$('div#header input.button').hover(
	function(){
		if($.browser.msie==true){
			$(this).css('cursor','hand');
		}else{
			$(this).css('cursor','pointer');
		}
	}
	,
	function(){
		$(this).css('cursor','default');
	}
	)
});

function stream(test){
	alert(test)
}

function add_vote_positif_action(){
	$('a.vote-positif').click(function(){
		
		$('#tooltipHelper').hide();
		if($(this).attr('rel')=='done'){
			votepts = 2;
		}else{
			votepts = 1;
		}
		value = {
			id:$(this).attr('id').split('-')[1],
			vote:votepts	
		};
		$.post("/public/ajax/update-vote.php",value,callback_vote_action);
		
		return false;
	});
	
	$('a.vote-positif').tooltip({ 
								    track: true, 
								    delay: 200, 
								    showURL: false, 
								    showBody: " - ",
									extraClass:'inputsTooltipPositif', 
								    opacity: 0.85 
								});
}

function add_vote_negatif_action(){
	$('a.vote-negatif').click(function(){
		$('#tooltipHelper').hide();
		if($(this).attr('rel')=='done'){
			votepts = -2;
		}else{
			votepts = -1;
		}
		value = {
			id:$(this).attr('id').split('-')[1],
			vote:votepts	
		};
		$.post("/public/ajax/update-vote.php",value,callback_vote_action);
		return false;
	});
	$('a.vote-negatif').tooltip({ 
								    track: true, 
								    delay: 200, 
								    showURL: false, 
								    showBody: " - ",
									extraClass:'inputsTooltipNegatif', 
								    opacity: 0.85 
								});
}

function callback_vote_action(data){
	toadd  = data.split('-')[2];
	id   = data.split('-')[1];
	data = data.split('-')[0];
	if(data == 'positif' || data=='negatif'){
		if(data == 'positif'){
			pts = parseInt($('.points .big').text())+parseInt(toadd);
			$('.points .big').text(pts);
			
			//on switch les boutons
			$('a.vote-positif').after('<span class="vote-positif" id="positif-'+id+'">Vote positif</span>');
			$('a.vote-positif').remove();
			$('a.vote-negatif').attr('rel','done');
			if($('span.vote-negatif').length>0){
				$('span.vote-negatif').after('<a href="/" class="vote-negatif" id="negatif-'+id+'" title="Ce vid&eacute;o est mauvais. Je veux lui enlever un point!" rel="done">Vote n&eacute;gatif</a>');
				$('span.vote-negatif').remove();
				add_vote_negatif_action();
			}
			
		}else if(data=='negatif'){
			pts = parseInt($('.points .big').text())-parseInt(toadd);
			$('.points .big').text(pts);
			
			//on switch les boutons
			$('a.vote-negatif').after('<span class="vote-negatif" id="negatif-'+id+'">Vote n&eacute;gatif</span>');
			$('a.vote-negatif').remove();
			$('a.vote-positif').attr('rel','done');
			if($('span.vote-positif').length>0){
				$('span.vote-positif').after('<a href="/" class="vote-positif" id="positif-'+id+'" title="Ce vid&eacute;o est excellent. Je veux lui donner un point!" rel="done">Vote positif</a>');
				$('span.vote-positif').remove();
				add_vote_positif_action();
			}
		}
	}
}

function add_search_action(){
	$('#field_recherche').focus(function(){
		$(this).val("");
	});	
}

function echeck(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	  // alert("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	  // alert("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	   // alert("Invalid E-mail ID")
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	  //  alert("Invalid E-mail ID")
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	   // alert("Invalid E-mail ID")
	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	   // alert("Invalid E-mail ID")
	    return false
	 }
	
	 if (str.indexOf(" ")!=-1){
	   // alert("Invalid E-mail ID")
	    return false
	 }

		 return true					
}