var brancaMentaFE = jQuery.noConflict();

//dichiarazione testi modi
var URLtemplate = 'http://www.brancamenta.com/wp-content/themes/brancamenta/';
var URLsite = 'http://www.brancamenta.com/';
var modo01ita = '<img src="'+URLtemplate+'images/label-01.png" alt="" /><br/>1/5 di Brancamenta<br/>4/5 di Sprite<br/><br/>Versare direttamente Brancamenta in un tumbler alto. Riempire con Sprite gelata. Aggiungere una fettina di lime.';
var modo02ita = '<img src="'+URLtemplate+'images/label-04.png" alt="" /><br/>1/3 di Brancamenta<br/>1/3 di Red Bull<br/>1/3 di birra chiara leggera<br/><br/>3 cubetti di ghiaccio. Versare lentamente in un ampio bicchiere i prodotti freddi sul ghiaccio. Decorare con una scorza di limone. Servire con una cannuccia corta.';
var modo03ita = '<img src="'+URLtemplate+'images/label-03.png" alt="" /><br/>1/5 Brancamenta<br/>2/5 di succo di pompelmo<br/>2/5 succo d\'ananas<br/><br/>Adagiare dei cubetti di ghiaccio in un tumbler alto; versare Brancamenta e aggiungere i succhi di frutta. Miscelare, e decorare con un rametto di menta.';
var modo04ita = '<img src="'+URLtemplate+'images/label-02.png" alt="" /><br/>1/5 di Brancamenta<br/>4/5 di Tonic<br/>1/2 lime spremuto<br/><br/>Tanto ghiaccio e foglie di menta come guarnizione.';

var modo01eng = '<img src="'+URLtemplate+'images/label-01.png" alt="" /><br/>1/5 Brancamenta<br/>4/5 Sprite<br/><br/>Pour Brancamenta straight into a tall tumbler. Fill with ice cold Sprite. Add a slice of lime.';
var modo02eng = '<img src="'+URLtemplate+'images/label-04.png" alt="" /><br/>1/3 Brancamenta<br/>1/3 di Red Bull<br/>1/3 di birra chiara leggera<br/><br/>3 cubetti di ghiaccio. Versare lentamente in un ampio bicchiere i prodotti freddi sul ghiaccio. Decorare con una scorza di limone. Servire con una cannuccia corta.';
var modo03eng = '<img src="'+URLtemplate+'images/label-03.png" alt="" /><br/>1/5 Brancamenta<br/>2/5 grapefruit juice<br/>2/5 pineapple juice<br/><br/>Put some ice cubes in a tall tumbler; pour in the Brancamenta and add the fruit juices.Mix and decorate with a sprig of mint.';
var modo04eng = '<img src="'+URLtemplate+'images/label-02.png" alt="" /><br/>1/5 Brancamenta<br/>4/5 Tonic<br/>Half a squeezed lime<br/><br/>Garnished with plenty of ice and mint leaves.';


//dichiarazione gallery video

//gallery spot home
var spotFLV = new Array(URLsite+'flash/30_mix.flv');
var spotIMG = new Array(URLsite+'flash/video01.jpg');
var spotTitle = new Array('');
var spotDescription = new Array('');

//gallery comunicazione
var spotComunicazioneFLV = new Array(URLsite+'flash/15_mix.flv', '/flash/30_mix.flv');
var spotComunicazioneIMG = new Array(URLsite+'flash/15_mix.jpg', '/flash/30_mix.jpg');
var spotComunicazioneTitle = new Array('Spot \'\'15', 'Spot \'\'30');
var spotComunicazioneDescription = new Array('', '');


function ShowCondition(condition, idElement){
	if(condition == 1){
		doExternalAction(1, 1);
		brancaMentaFE("#"+idElement).hide();
	}else{
		brancaMentaFE("#condition-1").show();
		
	}
	
	
}

function swapImgOff(obj){
	var littleImg = obj.attr('src');
	if(littleImg.indexOf("IMGon") != -1){
		littleImg = littleImg.replace('IMGon', 'IMGoff');
	}
	obj.attr('src', littleImg);
	//alert(littleImg);
}
function swapImgOn(obj){
	var littleImg = obj.attr('src');
	if(littleImg.indexOf("IMGoff") != -1){
		littleImg = littleImg.replace('IMGoff', 'IMGon');
	}
	obj.attr('src', littleImg);
	//alert(littleImg);
}

function showBigImg(obj, idImgBig){
	var littleImg = obj.attr('src');
	var bigImg = "";
	if(littleImg.indexOf("IMGoff") != -1){
		bigImg = littleImg.replace('IMGoff', 'big');
	}else{
		bigImg = littleImg.replace('IMGon', 'big');
	}
	brancaMentaFE("#"+idImgBig).attr('src', bigImg);
}

function showText(obj){
	var textMod = eval(obj.attr('id'));
	brancaMentaFE("#modoTesto").html(textMod);
}


function slidePage(idPage){
	if(idPage != null){
		if(brancaMentaFE.browser.safari){ bodyelem = brancaMentaFE("body") } else{ bodyelem = brancaMentaFE("html,body") }
		var pos = brancaMentaFE('#'+idPage);
		var position = pos.position();
		var y = position.top -100;
		bodyelem.animate({scrollTop : y},1000);
	}
}

/*function writeFlasEmbed(){
	var embedCode = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="banner_2" width="500" align="middle" height="280"><param name="wmode" value="transparent"><param name="allowScriptAccess" value="sameDomain">	<param name="allowFullScreen" value="false">	<param name="movie" value="flash/PaintBall.swf">	<param name="quality" value="high">	<param name="bgcolor" value="#000000">	<embed style="visibility: visible;" src="flash/PaintBall.swf" wmode="transparent" quality="high" bgcolor="#000000" name="banner_2" allowscriptaccess="sameDomain" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" width="500" align="middle" height="280"></object>';
	brancaMentaFE('#spot').html(embedCode);
}
*/

function videoPlayer(idContainer, idVideo, pfxGallery){
	var varToLoad = eval(pfxGallery+'FLV[idVideo]');
	var imageToLoad = eval(pfxGallery+'IMG[idVideo]');
	
	//var embedCode = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="banner_2" width="500" align="middle" height="280"><param name="wmode" value="transparent"><param name="allowScriptAccess" value="sameDomain"><PARAM NAME=FlashVars VALUE="flvToPlay='+varToLoad+'"><param name="allowFullScreen" value="false">	<param name="movie" value="flash/playerVideo3.swf">	<param name="quality" value="high">	<param name="bgcolor" value="#000000">	<embed style="visibility: visible;" src="flash/playerVideo3.swf" FlashVars="flvToPlay='+varToLoad+'" wmode="transparent" quality="high" bgcolor="#000000" name="banner_2" allowscriptaccess="sameDomain" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" width="500" align="middle" height="280"></object>';
	//brancaMentaFE('#'+idContainer).html(embedCode);
	//var so = new SWFObject('flash/player.swf','mpl','500','301','9'); Dimensioni originali del video - Prima Release
	var so = new SWFObject(URLsite+'flash/player.swf','mpl','440','270','9');
	
	so.addParam('allowfullscreen','true');
	
	so.addParam('allowscriptaccess','always');
	so.addParam('wmode','opaque');
	so.addVariable('file',varToLoad);
	so.addVariable('image',imageToLoad);
	so.addVariable('autostart','false');
	
	if(brancaMentaFE("#"+idContainer).html() != null){
		so.write(idContainer);	
	}
	
	
	videoNav(idContainer, idVideo, pfxGallery);
	brancaMentaFE('#'+idContainer+'Title').html(eval(pfxGallery+'Title[idVideo]'));
	brancaMentaFE('#'+idContainer+'Description').html(eval(pfxGallery+'Description[idVideo]'));
}

function videoNav(idContainer, idVideoCurrent, pfxGallery){	
	brancaMentaFE('#'+idContainer+'Next').show();
	brancaMentaFE('#'+idContainer+'Prev').show();
	if(eval(pfxGallery+'FLV.length') <= 1){
		brancaMentaFE('#'+idContainer+'Nav').hide();
	}else{
		if(idVideoCurrent ==  0){
			brancaMentaFE('#'+idContainer+'Prev').hide();
		}
		if(idVideoCurrent == (eval(pfxGallery+'FLV.length-1'))){
			brancaMentaFE('#'+idContainer+'Next').hide();
		}
		brancaMentaFE('#'+idContainer+'Next').attr('href', 'javascript:videoPlayer("'+idContainer+'", '+(idVideoCurrent+1)+', "'+pfxGallery+'")');
		brancaMentaFE('#'+idContainer+'Prev').attr('href', 'javascript:videoPlayer("'+idContainer+'", '+(idVideoCurrent-1)+', "'+pfxGallery+'")');
	}
	
}

function checkAncor(){	
	var ancor;
	var docURL;
	docURL = document.URL;
	ancor = docURL.split("#");
	if(ancor[1] != "undefine"){
		slidePage(ancor[1]);
	}
}
function setLanguage(lang){	
	doExternalAction(2, lang);
	window.location.reload();
}
function setLanguagePage(lang){	
	doExternalAction(2, lang);
	window.location = "/";
}


function selectTappe(idTappa){
	
	brancaMentaFE.post("/externalCall.php", { act:3, idTappa: idTappa},
	   function(data){
			//alert(data);
			brancaMentaFE('#listTappe').html(data);
	   });
}



function doExternalAction(action, arg){
	brancaMentaFE.post("/externalCall.php", { act:action, argument: arg},
	   function(data){
			//alert(data);
	});
}

brancaMentaFE(document).ready(function () {
	checkAncor();
	//alert(brancaMentaFE("#lang").val());
	//setto modi a 1
	
	brancaMentaFE('#modo01').attr("src", "/wp-content/themes/brancamenta/images/01-IMGon.png");
	
	brancaMentaFE("#modoTesto").html(eval("modo01"+brancaMentaFE("#lang").val()));


	

	//videoplayer('id div contenitore player', 'l'indice del video di start', 'prefizzo nome gallery video')

	// inizializzazione player spot home 
	
	videoPlayer('spot', 0, 'spot');
	
	// inizializzazione player comunicazione
	videoPlayer('spotComunicazione', 0, 'spotComunicazione');
	
	
	brancaMentaFE('.previewImgModi').mouseover(function() {
		swapImgOn(brancaMentaFE(this));
		showBigImg(brancaMentaFE(this), 'modi-Img');
		showText(brancaMentaFE(this));
	});
	brancaMentaFE('.previewImgModi').mouseout(function() {
		swapImgOff(brancaMentaFE(this));
	});
	
	
	
	brancaMentaFE("#menu > li > a").click(function() {
		brancaMentaFE("#menu > li > a").removeClass('active');
		brancaMentaFE(this).addClass('active');
	});
	

	
});


