$(window).ready(function(){ 
	var hcday = document.getElementById('cday');
	var cday = hcday ? hcday.value - 1 : 0;
	$('#sponsored-content').each(function(){
		this.style.width = $(window).width() + 'px';
		this.style.height = $(document).height() + 'px';
		this.style.display = 'block';
		$("a#closeSponsor").click(function(){ $('#sponsored-content').slideUp(2000, function(){ $(this).remove(); }); });
		setTimeout(function(){ $('#sponsored-content').slideUp(2000, function(){ $(this).remove(); }); }, 8000);
		$("#swf_sponsor input.swf_banner").each(function(){
			var value = this.value.split('|');	
			swfobject.embedSWF(value[0], value[1], "600", "500", "8.0.0", "/media/expressInstall.swf", { }, { wmode:"opaque" }, { });
		});			
	});
	$('#mgallery .slideshow').serialScroll({
		items:'li',prev:'#mgallery .controlls a.prev', next:'#mgallery .controlls a.next', offset:5, start:0, duration:1200,
		force:true, stop:true, lock:false, cycle:true, easing:'easeOutQuart', jump: true,
		onAfter:function(elem){			
			var items = $("ul li", $(this));
			var n = items.length;
			$('#mgallery .controlls span').html((items.index(elem) + 1) + ' / ' + n);
		}
	});
	$('#cont1 .slideshow').serialScroll({
		items:'div.jor', prev:'#cont1 .controlls a.prev', next:'#cont1 .controlls a.next', offset:0, start: cday, duration:1200,
		force:true, stop:true, lock:false, cycle:false, easing:'easeOutQuart', jump: true,
		onBefore:function(event, elem){			
			var items = $("#cont1 .strip .jor");
			var n = items.length;
			$('#cont1 .controlls span').html('Jornada ' + (items.index(elem) + 1));
		}
	});
	$('.gallery .hiddenContent .slideshow').serialScroll({
		items:'div.content', prev:'.gallery .hiddenContent .controlls a.prev', next:'.gallery .hiddenContent .controlls a.next', offset:0,
		start: 0, duration:1200, force:true, stop:true, lock:false, cycle:false, easing:'easeOutQuart', exclude: 1,	jump: true,
		onBefore:function(event, elem){			
			var items = $("#TB_ajaxContent .slideshow .strip div.content");
			var n = items.length;	
			x = items.index(elem) + 1;
			if(x != 0)
				$('#TB_ajaxContent .controlls span').html((x + 1 == n ? n : x) + '/' + n);
		}
	});	
	$('select.onchange_submit').change(function(){
		document.location.href = this.form.action +  this.value;
	});
	$('div.tabs a').click(function(){
		var tar = $("div.tabs a").index(this);
		$('#pools div.cont').each(function(i){
			this.className = (i == tar) ? 'cont show' : 'cont hide';
		});
	});	
	$('form#poll input#rsee').click(function(){
		$("form#poll ul.poll input").each(function(){ this.cheched = false });
		$("form#poll").get(0).submit();
	});
	$('form#poll input#vote').click(function(){
		if($("form#poll ul.poll input:checked").length) 
			$("form#poll").get(0).submit();
	});
	$("#swf_main input.swf_banner").each(function(){
		var value = this.value.split('|');	
		var action = value[2] ? "window.open('/actions/click.php?id=" + value[2] + "')" : null;
		swfobject.embedSWF(value[0], value[1], "450", "80", "8.0.0", "/media/expressInstall.swf", { }, { wmode:"opaque"  }, { onclick: action });					
	});
	$("#swf_second input.swf_banner").each(function(){
		var value = this.value.split('|');	
		var action = value[2] ? "window.open('/actions/click.php?id=" + value[2] + "')" : null;
		swfobject.embedSWF(value[0], value[1], "150", "80", "8.0.0", "/media/expressInstall.swf", { }, { wmode:"opaque"  }, { onclick: action });					
	});	
	$("div.banners div.item").each(function(){
		$('input.swf_banner', $(this)).each(function(){
			var value = this.value.split('|');
			var action = value[2] ? "window.open('/actions/click.php?id=" + value[2] + "')" : null;			
			swfobject.embedSWF(value[0], value[1], "170", "170", "8.0.0", "/media/expressInstall.swf", { }, { wmode:"opaque" }, { onclick: action });			
		});
	});
	var dti = $("input#i");
	if(dti.length) dti.datepicker({ dateFormat:'dd-mm-yy'}); 
	var dte = $("input#e");
	if(dte.length) dte.datepicker({ dateFormat:'dd-mm-yy'}); 
	$("div.rightbar div.banner").each(function(){
		$('input.swf_banner', $(this)).each(function(){
			var value = this.value.split('|');
			var action = value[2] ? "window.open('/actions/click.php?id=" + value[2] + "')" : null;
			$("div.banners .item").each(function(){
				$('input.swf_banner', $(this)).each(function(){
					var value = this.value.split('|');
					var action = value[2] ? "window.open('/actions/click.php?id=" + value[2] + "')" : null;			
					swfobject.embedSWF(value[0], value[1], "170", "170", "8.0.0", "/media/expressInstall.swf", { }, { wmode:"opaque" }, { onclick: action });
				});
			});
			swfobject.embedSWF(value[0], value[1], "250", "250", "8.0.0", "/media/expressInstall.swf", { }, { wmode:"opaque" }, { onclick: action });
		});
	});	
	$("div.hiddenContent .slideshow").each(function(){
		$('input.swf_gallery', $(this)).each(function(){
			var value = this.value.split('|');
			var flashvars = { file: value[1], image: value[2], type: value[3] };
			swfobject.embedSWF("/media/player.swf", value[0], "400", "300", "8.0.0", "/media/expressInstall.swf", flashvars, { wmode:"opaque" }, { });
		});
	});		
	$('div.cover .content').mouseover(function(){ $('div#sponsor').animate({ marginTop:'189px'}, {queue:false, duration:500}); }).mouseout(function(){ $('div#sponsor').animate({ marginTop:'234px'}, {queue:false, duration:500}); });	
	if(jQuery.browser.msie) $('div.tabs a:first').trigger('click');
	$('#tk').change(function(){ var enab = this.checked; $('#scosts').each(function(){ this.disabled = enab; }); });
	$('a[rel=nofollow]').attr('target', '_blank'); 
	$('a#eml').each(function(){ var head = 'i' + 'n' + 'fo' + '\x40'; this.href = 'mailto:' + head + 'menorcabasquet' + '%2e%63%6f%6d'; this.innerHTML =  head + 'menorcabasquet' + '&#46;&#99;&#111;&#109'; });
});

function go(url){
	document.location.href = url;
}

function openGallery(offset){
	setTimeout("$('#TB_ajaxContent .slideshow').trigger( 'goto', " + eval(offset) + ");", 1000);
}

