var uno = 0;

function vote(val, id)
{
	if (val == -1)
		return;
	$('#pouce_oui_'+id).attr('href', 'javascript:vote(-1, 0)');
	$('#pouce_non_'+id).attr('href', 'javascript:vote(-1, 0)');
	console.log(themeURL+"/vote.php?val="+val+"&id="+id);
	$.ajax({
		  url: themeURL+"/vote.php?val="+val+"&id="+id,
		  success: function(data){
			console.log(data);
			if (data == 'ok')
			{
				if (val == 0)
					$('#non_'+id).html(parseInt($('#non_'+id).html(), 10)+1);
				if (val == 1)
					$('#oui_'+id).html(parseInt($('#oui_'+id).html(), 10)+1);
			}
		}
	});
}

function affPhotos()
{
	$('#videosHome').hide();
	$('#photosHome').show();
}

function affVideos()
{
	$('#videosHome').show();
	$('#photosHome').hide();
}

function changeVideo(id)
{
	ytswf = document.getElementById('myytplayer');
	ytswf.loadVideoById(id, 0, 'default');	
}

function changeVideos(id, firstVideo)
{
	$('#ongletVideos .current').removeClass('current');
	$('#onglet-'+id).addClass('current');
	$('#videosHome .carrousel-cyclique').each(function(){$(this).hide();})
	$('#mon-carrousel-'+id).show();
	changeVideo(firstVideo);
}

function changePhotos(id)
{
	$('#ongletPhoto .current').removeClass('current');
	$('#onglet-'+id).addClass('current');
	$('#playerPhoto').html('<object width="468" height="351"> <param name="flashvars" value="offsite=true&lang=fr-fr&page_show_url=%2Fphotos%2Folympique-et-lyonnais%2Fsets%2F'+id+'%2Fshow%2F&page_show_back_url=%2Fphotos%2Folympique-et-lyonnais%2Fsets%2F'+id+'%2F&set_id='+id+'&jump_to="></param> <param name="movie" value="http://www.flickr.com/apps/slideshow/show.swf?v=104087"></param> <param name="allowFullScreen" value="true"></param><embed type="application/x-shockwave-flash" src="http://www.flickr.com/apps/slideshow/show.swf?v=104087" allowFullScreen="true" flashvars="offsite=true&lang=fr-fr&page_show_url=%2Fphotos%2Folympique-et-lyonnais%2Fsets%2F'+id+'%2Fshow%2F&page_show_back_url=%2Fphotos%2Folympique-et-lyonnais%2Fsets%2F'+id+'%2F&set_id='+id+'&jump_to=" width="468" height="351"></embed></object>');
}
	
$(document).ready(function(){
    
	

/* $("#main").everyTime(5000,function() {
		
		if(uno<3){  
		$('span.une'+uno).fadeOut('slow');
		$('span.une'+(uno+1)).fadeIn('slow');
		uno++;
		}
		else {
		$('span.une'+uno).fadeOut('slow');
		$('span.une0').fadeIn('slow');
		uno=0;
		}
     });*/

	//loadVideoById(idOrUrl, parseInt(startSeconds), quality);
	$('#aff_add_sujet').click(function()
	{
		$('#add_sujet').show();
		return false;
	});
   	 $('.carrousel-cyclique').each(function()
	 {
		 carrouselCyclique($(this).attr('id'),3,149,500);
	 });
	 
	 $('.item-cyclique').hover(function(){
		 $(this).append('<a href="'+$(this).children('a').attr('href')+'" class="hoverIcone">'+$(this).children('a').attr('title')+'</a>');
	 }, function () {
		 $(this).children('.hoverIcone').remove();
	 });
	 
	jQuery('.carrousel-cyclique .prev').hover(function(){jQuery(this).animate({'opacity':0.5});}, function(){jQuery(this).animate({'opacity':1});});
	jQuery('.carrousel-cyclique .next').hover(function(){jQuery(this).animate({'opacity':0.5});}, function(){jQuery(this).animate({'opacity':1});});

	 
	 //menu match
	 $('#plusmenu').toggle(
      function () {
			$('#top').animate({"height": "+=120px"}, "fast");
      },
	  function() {
		    $('#top').animate({"height": "-=120px"}, "fast");
	  }
	 );
	 
	 //menu_effectif
	
	
	//menu club
	 $('#menu_club').hover(
      function () {
		    $('#mainnavigation img').css('top','38px');
			$('#menu_club img').css('top','-38px');
       		$('ul.ssmenu').hide();
			$('#ssmenu_club').show();
      },
	  function() {
		  $(this).animate({"opacity": 1.0}, 10000,function(){$('#ssmenu_club').fadeOut(function(){$('#menu_club img').css('top','0px')})});
	  }
	 );
	
	//menu compet
	$('#menu_competition').hover(
      function () {
		  	$('#mainnavigation img').css('top','38px');
			$('#menu_competition img').css('top','-38px');
       		$('ul.ssmenu').hide();
			$('#ssmenu_competition').show();
      },
	  function() {
		   $(this).animate({"opacity": 1.0}, 10000,function(){$('#ssmenu_competition').fadeOut(function(){$('#menu_competition img').css('top','0px')})});
	  }
	 );
	
	$('#menu_mercato').hover(
      function () {
	 		$('#mainnavigation img').css('top','38px');
			$('#menu_mercato img').css('top','-38px');
       		$('ul.ssmenu').hide();
			$('#ssmenu_mercato').show();
      },
	  function() {
		  $('#menu_mercato img').css('top','38px');
	  }
	 );
	
	$('#menu_video').hover(
      function () {
		    $('#mainnavigation img').css('top','38px');
			$('#menu_video img').css('top','-38px');
       		$('ul.ssmenu').hide();
			$('#ssmenu_video').show();
      },
	  function() {
		  $('#menu_video img').css('top','38px');
	  }
	 );
	
		$('#menu_boutique').hover(
      function () {
		    $('#mainnavigation img').css('top','38px');
			$('#menu_boutique img').css('top','-38px');
       		$('ul.ssmenu').hide();
			$('#ssmenu_boutique').show();
      },
	  function() {
		  $('#menu_boutique img').css('top','38px');
	  }
	 );
		
		$('#menu_pronostic').hover(
      function () {
		  $('#mainnavigation img').css('top','38px');
			$('#menu_pronostic img').css('top','-38px');
       		$('ul.ssmenu').hide();
			$('#ssmenu_pronostic').show();
      },
	  function() {
		  $('#menu_pronostic img').css('top','38px');
	  }
	 );

   
   

	
	/*
	** FIL ACTU
	*/
	jQuery('.cat_fil_actu a').hover(function()
	{
		var id = jQuery(this).attr('id').substr(10);
		jQuery('.art_fil_actu .current').removeClass('current');
		jQuery('.cat_fil_actu .current').removeClass('current');
		jQuery(this).addClass('current');
		jQuery('.art_fil_actu #fil_actu_'+id).addClass('current');
		return false;
	});

	jQuery('#more_fil_actu').hover(function(){jQuery(this).animate({'opacity':0.5});}, function(){jQuery(this).animate({'opacity':1});jQuery('.art_fil_actu .current').stop();});
	jQuery('#less_fil_actu').hover(function(){jQuery(this).animate({'opacity':0.5});}, function(){jQuery(this).animate({'opacity':1});jQuery('.art_fil_actu .current').stop();});
	
	jQuery('#more_fil_actu').mousedown(
		function()
		{
			var totalMove = (-1 * jQuery('.art_fil_actu .current').height()) + jQuery('.art_fil_actu').height();
			var reste = (totalMove * -1) + parseInt(jQuery('.art_fil_actu .current').css('margin-top'), 10);
			jQuery('.art_fil_actu .current').animate({'margin-top':totalMove+'px'}, reste * 5);
		}).mouseup(function()
		{
			jQuery('.art_fil_actu .current').stop();
		});


  	jQuery('#less_fil_actu').mousedown(
		function()
		{
			var totalMove = 0;
			var reste = -1 * parseInt(jQuery('.art_fil_actu .current').css('margin-top'), 10);
			jQuery('.art_fil_actu .current').animate({'margin-top':totalMove+'px'}, reste * 5);
		}).mouseup(function()
		{
			jQuery('.art_fil_actu .current').stop();
		}
	);
	
	jQuery('.widget_lastforum img').hover(function(){jQuery(this).animate({'opacity':0.5});}, function(){jQuery(this).stop();jQuery(this).css({'opacity':1});});
  //fin domready
  });


function playvideo(video,id){
						$('#videoplayer').html('<object type="application/x-shockwave-flash" data="/inc/flash/player_flv_multi.swf" width="480" height="360">'+
					   '<param value="/inc/flash/player_flv_multi.swf" name="movie">'+
					   '<param value="flv='+video+'&config=/inc/flash/configvideo_player.txt" name="FlashVars">'+
					   '<param></object>');
						$('#mycarousel a').css('font-weight','normal');
						$('#'+id+'').css('font-weight','bold');

}







function prev() {
    $('#nextcontent').css('display','none');
	$('#agenda').css('background-position','left -182px');
	$('#nextm a').css('color','#CCC');
	$('#prevm a').css('color','#0071BC');
	//$('#ulcomments').hide();
	//$('#ularticles').hide();
	$('#prevcontent').show();
	
	
	return false;
}
function next() {
    $('#nextcontent').css('display','block');
	$('#agenda').css('background-position','left 0px');
	$('#prevm a').css('color','#CCC');
	$('#nextm a').css('color','#0071BC');
	//$('#ulcomments').hide();
	//$('#ularticles').hide();
	$('#prevcontent').hide();
	
	
	return false;
}
function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function serialize (txt) {
	switch(typeof(txt)){
	case 'string':
		return 's:'+txt.length+':"'+txt+'";';
	case 'number':
		if(txt>=0 && String(txt).indexOf('.') == -1 && txt < 65536) return 'i:'+txt+';';
		return 'd:'+txt+';';
	case 'boolean':
		return 'b:'+( (txt)?'1':'0' )+';';
	case 'object':
		var i=0,k,ret='';
		for(k in txt){
			//alert(isNaN(k));
			if(!isNaN(k)) k = Number(k);
			ret += serialize(k)+serialize(txt[k]);
			i++;
		}
		return 'a:'+i+':{'+ret+'}';
	default:
		return 'N;';
		alert('var undefined: '+typeof(txt));return undefined;
	}
}

function unserialize(data){
    // http://kevin.vanzonneveld.net
    // +     original by: Arpad Ray (mailto:arpad@php.net)
    // +     improved by: Pedro Tainha (http://www.pedrotainha.com)
    // +     bugfixed by: dptr1988
    // +      revised by: d3x
    // +     improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // %            note: We feel the main purpose of this function should be to ease the transport of data between php & js
    // %            note: Aiming for PHP-compatibility, we have to translate objects to arrays 
    // *       example 1: unserialize('a:3:{i:0;s:5:"Kevin";i:1;s:3:"van";i:2;s:9:"Zonneveld";}');
    // *       returns 1: ['Kevin', 'van', 'Zonneveld']
    // *       example 2: unserialize('a:3:{s:9:"firstName";s:5:"Kevin";s:7:"midName";s:3:"van";s:7:"surName";s:9:"Zonneveld";}');
    // *       returns 2: {firstName: 'Kevin', midName: 'van', surName: 'Zonneveld'}
    
    var error = function (type, msg, filename, line){throw new window[type](msg, filename, line);};
    var read_until = function (data, offset, stopchr){
        var buf = [];
        var chr = data.slice(offset, offset + 1);
        var i = 2;
        while(chr != stopchr){
            if((i+offset) > data.length){
                error('Error', 'Invalid');
            }
            buf.push(chr);
            chr = data.slice(offset + (i - 1),offset + i);
            i += 1;
        }
        return [buf.length, buf.join('')];
    };
    var read_chrs = function (data, offset, length){
        buf = [];
        for(var i = 0;i < length;i++){
            var chr = data.slice(offset + (i - 1),offset + i);
            buf.push(chr);
        }
        return [buf.length, buf.join('')];
    };
    var _unserialize = function (data, offset){
        if(!offset) offset = 0;
        var buf = [];
        var dtype = (data.slice(offset, offset + 1)).toLowerCase();
        
        var dataoffset = offset + 2;
        var typeconvert = new Function('x', 'return x');
        var chrs = 0;
        var datalength = 0;
        
        switch(dtype){
            case "i":
                typeconvert = new Function('x', 'return parseInt(x)');
                var readData = read_until(data, dataoffset, ';');
                var chrs = readData[0];
                var readdata = readData[1];
                dataoffset += chrs + 1;
            break;
            case "b":
                typeconvert = new Function('x', 'return (parseInt(x) == 1)');
                var readData = read_until(data, dataoffset, ';');
                var chrs = readData[0];
                var readdata = readData[1];
                dataoffset += chrs + 1;
            break;
            case "d":
                typeconvert = new Function('x', 'return parseFloat(x)');
                var readData = read_until(data, dataoffset, ';');
                var chrs = readData[0];
                var readdata = readData[1];
                dataoffset += chrs + 1;
            break;
            case "n":
                readdata = null;
            break;
            case "s":
                var ccount = read_until(data, dataoffset, ':');
                var chrs = ccount[0];
                var stringlength = ccount[1];
                dataoffset += chrs + 2;
                
                var readData = read_chrs(data, dataoffset+1, parseInt(stringlength));
                var chrs = readData[0];
                var readdata = readData[1];
                dataoffset += chrs + 2;
                if(chrs != parseInt(stringlength) && chrs != readdata.length){
                    error('SyntaxError', 'String length mismatch');
                }
            break;
            case "a":
                var readdata = {};
                
                var keyandchrs = read_until(data, dataoffset, ':');
                var chrs = keyandchrs[0];
                var keys = keyandchrs[1];
                dataoffset += chrs + 2;
                
                for(var i = 0;i < parseInt(keys);i++){
                    var kprops = _unserialize(data, dataoffset);
                    var kchrs = kprops[1];
                    var key = kprops[2];
                    dataoffset += kchrs;
                    
                    var vprops = _unserialize(data, dataoffset);
                    var vchrs = vprops[1];
                    var value = vprops[2];
                    dataoffset += vchrs;
                    
                    readdata[key] = value;
                }
                
                dataoffset += 1;
            break;
            default:
                error('SyntaxError', 'Unknown / Unhandled data type(s): ' + dtype);
            break;
        }
        return [dtype, dataoffset - offset, typeconvert(readdata)];
    };
    return _unserialize(data, 0)[2];
}
