//javascript

//submit pedido
function pagar(form) {
	//window.open('', 'formpopup', 'width=600,height=460,resizeable,scrollbars');
    //form.target = 'formpopup';
	var width = 600;
    var height = 460;
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + height + ",status,resizable,scrollbars,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top;
	myWindow = window.open('', "formpopup", windowFeatures);
	//window.open('', 'formpopup', 'width=600,height=460,resizeable,scrollbars');
    form.target = 'formpopup';
}

/* SUBMENUS */

eshome=0;
menuactiu = 0;
function submenu(id) {
	//timer
	clearTimeout(timesub);
	timesub='';
	//si no hi ha cap actiu
	if (menuactiu==0) {
		menuactiu=id;
	}
	//si l'actiu es ell mateix
	else if (menuactiu==id) {
		menuactiu=0;
	}
	//l'actiu es l'altre
	else {
		$('#'+menuactiu).animate({opacity: 'toggle'}, 'slow');
		menuactiu=id;
	}
	//toggle del que ens demanen
	$('#'+id).animate({opacity: 'toggle'}, 'slow');
}

timesub='';
function submenu_t(id) {
	if(timesub) {
		 clearTimeout(timesub);
		 timesub='';
	}
	else timesub=setTimeout("submenu('"+id+"')", 200);
}

function submenu_o(id) {
	timesub=setTimeout("submenu('"+id+"')", 200);
}

function submenu_a(id) {
	if(timesub) {
		 clearTimeout(timesub);
		 timesub='';
	}

}

/* CAROUSEL */

actual=1;
temps=4000;
tempsvi=3000;
scopy=0;
numelements=0;
numvinos=0;
jQuery(document).ready(function() {
	if(numelements) time=setTimeout(seguentelem, temps);
	if(numvinos>1) time=setTimeout(seguentvi, tempsvi);
});

function hide() {
	//toggle('copy'+actual);
	$('#fotocopy').hide();
	$('#copy'+actual).hide();
}

function show() {
	//toggle('copy'+actual);
	$('#fotocopy').show();
	$('#copy'+actual).show();
}

actvi=1;
function seguentvi() {
	//netejar timeout
	clearTimeout(time);
	//id actual
	ara = '#bot'+actvi;
	//id seguent
	seguent = actvi+1;
	if (seguent==numvinos+1) seguent = 1;
	despres = '#bot'+seguent;
	//fades
	$(ara).fadeOut("slow");
	$(despres).fadeIn("slow");
	//actualitzar actual
	actvi = seguent;
	//programar timeout
	time=setTimeout(seguentvi, tempsvi);
}
function seguentelem() {
	//netejar timeout
	clearTimeout(time);
	//id actual
	ara = '#item'+actual;
	//id seguent
	seguent = actual+1;
	if (seguent==numelements+1) seguent = 1;
	despres = '#item'+seguent;
	//fades
	$(ara).fadeOut("slow");
	$(despres).fadeIn("slow");
	if(scopy) {
		$('#copy'+scopy).fadeOut("slow");
		scopy=0;
	}
	//canviar radios
	$('#radio'+actual).attr("src","img/estructura/carousel/radio_off.png");
	$('#radio'+seguent).attr("src","img/estructura/carousel/radio_on.png");
	//actualitzar actual
	actual = seguent;
	//mirar si home
	if(eshome && seguent==3) temps=10000;
	else temps = 4000;
	//programar timeout
	time=setTimeout(seguentelem, temps);
	//hide copy
	hide();
}

function anteriorelem() {
	//netejar timeout
	clearTimeout(time);
	//id actual
	ara = '#item'+actual;
	//id seguent
	seguent = actual-1;
	if (seguent==0) seguent = numelements;
	despres = '#item'+seguent;
	//fades
	$(ara).fadeOut("slow");
	$(despres).fadeIn("slow");
	if(scopy) {
		$('#copy'+scopy).fadeOut("slow");
		scopy=0;
	}
	//canviar radios
	$('#radio'+actual).attr("src","img/estructura/carousel/radio_off.png");
	$('#radio'+seguent).attr("src","img/estructura/carousel/radio_on.png");
	//actualitzar actual
	actual = seguent;
	//programar timeout
	time=setTimeout(seguentelem, temps);
	//hide copy
	hide();
}

function toelem(id) {
	if(id!=actual) {
		//netejar timeout
		clearTimeout(time);
		//id actual
		ara = '#item'+actual;
		//id seguent
		seguent=id;
		despres = '#item'+id;
		//fades
		$(ara).fadeOut("slow");
		$(despres).fadeIn("slow");
		//canviar radios
		$('#radio'+actual).attr("src","img/estructura/carousel/radio_off.png");
		$('#radio'+seguent).attr("src","img/estructura/carousel/radio_on.png");
		//actualitzar actual
		actual = seguent;
		//programar timeout
		//time=setTimeout(seguentelem, temps);		
	}
}

function pause() {
	//netejar timeout
	clearTimeout(time);
}

function play() {
	time=setTimeout(seguentelem, temps);
}

timec='';
function tcopy() {
	if(scopy) scopy=0;
	else scopy=actual;
	if(timec) {
		 clearTimeout(timec);
		 timec='';
	}
	else timec=setTimeout(tcopydly, 200);
}

function tcopydly() {
	clearTimeout(timec);
	timec='';
	toggle('copy'+actual);
	toggle('fotocopy');
}

/* DETALLES BOTELLAS */

detall=0;
function detalle(id) {
	//si no hi ha cap actiu
	if (detall==0) {
		detall=id;
		//mostrar xapa blanca
		$('#detalle0').show();
	}
	//si l'actiu es ell mateix
	else if (detall==id) {
		detall=0;
		//ocultar xapa blanca
		$('#detalle0').hide();
	}
	//l'actiu es l'altre
	else {
		$('#detalle'+detall).animate({opacity: 'toggle'}, 'slow');
		detall=id;
	}
	//toggle del que ens demanen
	$('#detalle'+id).animate({opacity: 'toggle'}, 'slow');
	//ocultar carrito
	$('#carrito').hide();
}

/* EMPRESA */

function toggle(id) {
	//toggle del que ens demanen
	$('#'+id).animate({opacity: 'toggle'}, 'fast');
}

/* IFRAMES COLECTIVOS */

function iframe(src) {
	$('#negre').show();
	$('#iframe').show();
	$('#eliframe').attr("src",'pagines/'+src);
}

function closeiframe() {
	$('#negre').hide();
	$('#iframe').hide();
	$('#eliframe').attr("src",'pagines/negre.html');	
}

/* REGISTRO */

function oreg() {
	$('#negre').show();
	$('#registro').show();	
}
function creg() {
	$('#negre').hide();
	$('#registro').hide();	
}

/* NOTICICAS */

noticia=1;
function next() {
	seg=noticia+1;
	if(seg>numpnotis) seg=1;
	spanoti(seg);	
}

function prev() {
	seg=noticia-1;
	if(seg==0) seg=numpnotis;
	spanoti(seg);
}

function spanoti(seg) {
	toggle('bloque'+noticia);
	toggle('bloque'+seg);
	noticia=seg;
	$('#pag').text(noticia) 
}

/* vinos */

function go(url) {
	window.location='?p='+url;	
}

function govino(url) {
	window.location='?p=vino&sp='+url;	
}

function opremios() {
	$('#negre').show();
	$('#premios').show();	
}

function cpremios() {
	$('#negre').hide();
	$('#premios').hide();	
}

function oformatos() {
	$('#negre').show();
	$('#formatos').show();	
}
function cformatos() {
	$('#negre').hide();
	$('#formatos').hide();	
}

//altres

//centered popup window
var myWindow;
function finestra(url, width, height) {
    if (!width) var width = 600;
    if (!height) var height = 450;
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + height + ",status,resizable,scrollbars,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top;
    myWindow = window.open(url, "subWind", windowFeatures);
}



