/**
 *Ajoute un flash webcam a afficher
 */
flashs = new Array();
function addWebcamFlash(id,rating,recent){
    var index = flashs.length;
    flashs[index] = new Array();
    flashs[index]['id'] = id;
    flashs[index]['rating'] = rating;
    flashs[index]['recent'] = recent;
}

/**
 * Methode loadant un flash webcam sur un element
 */
function loadWebcamFlash(id,rating,recent){
    var flashvars = {
        "rating" : rating,
        "isNew" : recent,
        "isTop":"false",
        "href" : $('#'+id).parent().attr('href'),
        "target" : "_self"
    };
    var paramsSWF = {
        menu : "false",
        quality : "high",
        AllowScriptAccess : "always",
        wmode: "transparent"
    };
    var attributesSWF = {
        'class': 'transparent'
    }
    swfobject.embedSWF("http://media.the-adult-company.com/market2/market/campaign/freeones/flash/layer.swf", id, "160", "120", "9.0.0","http://media.the-adult-company.com/market2/market/campaign/freeones/flash/expressInstall.swf", flashvars, paramsSWF, attributesSWF);
}

function startStreamingThumb( url, div, livePicture ){
    var flowplayer = startStreaming(url,div,livePicture,{
        hideControls: true,
        initialVolumePercentage: 'mute',
        loop: true
    });
}

// lancement de la video en streaming
function startStreaming( url, div, livePicture, addConfig )
{
    if( typeof(flowplayers) == "undefined" ){
        flowplayers = Array();
    }
    if( typeof(addConfig) == "undefined" ) addConfig = new Array();

    var _config = {
        videoFile: url,
        name: url,
        autoPlay: true,
        autoBuffering: true,
        controlBarBackgroundColor:'0xE7E7E7',
        initialScale: 'fit',
        protected: true,
        menuItems:  [ true, true, true, true, true, false, false ],
        watermarkUrl : 'http://media.the-adult-company.com/market2/market/campaign/freeones/flash/trans.gif',
        showMenu: false,
        showFullScreenButton: false,
        loop: false,
        autoRewind: true,
        initialVolumePercentage: 20
    }
    for( var name in addConfig){
        _config[name] = addConfig[name];
    }

    if( typeof(livePicture) != "undefined" ){
        var _noVideoClip = {
            url: livePicture
        }
        _config['noVideoClip'] = _noVideoClip;
    }

    var flowplayer = flashembed(div,
    {
        src:'http://media.the-adult-company.com/market2/market/campaign/freeones/flash/FlowPlayerLight.swf',
        width: $('#'+div).width(),
        height: $('#'+div).height(),
        wmode: "transparent"
    },
    {
        config: _config
    }
    );
    flowplayers[url] = flowplayer;
    return flowplayer;
}

//Patch IE pour redirection lors du click sur la video
window.onPause = function(clip){
    var clipUrl = clip.baseUrl+"/"+clip.fileName;
    var splitted = clipUrl.split('?');
    if( splitted[1] ){
        document.location.href = splitted[1];
    }
}


Function.prototype.extend = function(source){
	 function initClassIfNecessary(obj) {
	 if( typeof obj["_super"] == "undefined" ) {
	 obj["_super"] = function() {
	 var methodName = arguments[0];
	 var parameters = arguments[1];
	 this["__parent_methods"][methodName].apply(this, parameters);
	 }
	 }
	 if( typeof obj["__parent_methods"] == "undefined" ) {
	 obj["__parent_methods"] = {}
	 }
	 }
	 for (var element in source.prototype) {
	 if( typeof this.prototype[element] != "undefined" ) {
	 initClassIfNecessary(this.prototype);
	 this.prototype["__parent_methods"][element] = source.prototype[element];
	 }else{
	 this.prototype[element] = source.prototype[element];
	 }
	 }
	 return this;
	 }

function pageparpage(formu,current) { document.forms[formu].current.value = current; $('#'+formu).submit(); }

function changeSearch(obj,val) { obj.value=val;$('#form_profil').submit(); }

function imgHoverGallchange(tab_im, tab_leg) {
	$("#imgHovSrc").fadeOut("normal");
	numim = parseInt($("#imgHoverGall").attr("currimgnum"));
	var img = new Image();
	$(img).load(function () {
			$("#imgHoverGall SPAN").html( tab_leg[0] + "<br/><img id='imgHovSrc' src='"+ tab_im[numim] +"' width='250px' style='display:none;' alt=''/>"  );
			$("#imgHoverGall").children('EM')
				.height( $("#imgHoverGall").children('SPAN').innerHeight() )
				.width( $("#imgHoverGall").children('SPAN').innerWidth() );
			numim = ( (numim+1)<tab_im.length ) ? numim+1 : 0 ;
			$("#imgHoverGall").attr( "currimgnum", numim );
			( $("#imgHoverGall").attr('timer')!='' ) ? clearTimeout( $("#imgHoverGall").attr('timer') ) : '';
			$("#imgHovSrc").fadeIn("normal");
			$("#imgHoverGall").attr('timer', setTimeout(function(){ imgHoverGallchange(tab_im, tab_leg); },2000) );
		})
		.attr( 'src', tab_im[numim] );
}

$(document).ready(function(){ 
	/* params for imgHoverGallchange */
	HautCurseur = 30;
	largCurseur = 10;
	maxW = document.body.clientWidth;//screen.availWidth;
	maxH = document.body.clientHeight;//screen.availHeight;

	$("a.imgHoverGall").each(function() {
		$(this).attr('t',this.title);
		this.title ='';
	})
	.hover(function(e){
		var tab_leg = ( $(this).attr('t').indexOf(';') > -1 ) ? $(this).attr('t').split(';') : new Array( $(this).attr('t') );
		var c = (tab_leg[0] != "") ? tab_leg[0]+"<br/>" : "";
		$("#imgHoverGall SPAN").html( c + "<br/><img id='imgHovSrc' src='http://media.the-adult-company.com/market2/market/campaign/freeones/img/loading.gif' width='50px' alt=''/>"  );
		var tab_im =  this.rel.split(';');
		if (tab_im.length>1)  {
			Haut = HautCurseur;	Larg = largCurseur;
			if ((e.pageY + 200) > maxH) {Haut = HautCurseur+221; }
			if ((e.pageX + 300) > maxW) {Larg = largCurseur-301; }
			$("#imgHoverGall")
				.css("top",(e.pageY - Haut) + "px")
				.css("left",(e.pageX + Larg) + "px")
				.fadeIn("normal")
				.attr("currimgnum",0);

			$("#imgHoverGall").children('EM')
				.height( $("#imgHoverGall").children('SPAN').innerHeight() )
				.width( $("#imgHoverGall").children('SPAN').innerWidth() );

			var img = new Image();
			$(img).load(function () {
					imgHoverGallchange(tab_im, tab_leg);
				})
				.attr( 'src', tab_im[0] );
		}
	},
	function(){
		if( $("#imgHoverGall").attr('timer')!='' ) clearTimeout( $("#imgHoverGall").attr('timer') );
		$("#imgHoverGall").css("display","none");
	})

	.mousemove(function(e){
		Haut = HautCurseur;	Larg = largCurseur;
		if ((e.pageY + 200) > maxH) {Haut = HautCurseur+221; }
		if ((e.pageX + 300) > maxW) {Larg = largCurseur-301; }
		$("#imgHoverGall")
			.css("top",(e.pageY - Haut) + "px")
			.css("left",(e.pageX + Larg) + "px");
	});

	
	
	// form infos
	$('#login_pseudo').one('focus', function(){
		$(this).val('');
	})
	$('#login_password').one('focus', function(){
		$(this).val('');
	})

	$('#current').addClass('selected');     // mainMenu
	$('#currentView').addClass('selected'); // viewMenu
	$('#currentPage').addClass('selected'); // navigation
});
