//carousel
function setCarousel1(id1){
	var car1=$("#"+id1)[0];
	var inner1=$("#"+id1+" ul")[0];
	var lis1=$("#"+id1+" ul li");
	var lisPad1=parseInt($(lis1[0]).css("padding-right"));
	$("#"+id1+" ul li:last").css({paddingRight:"0"});
	inner1.style.width=((lis1[0].offsetWidth)*lis1.length)-lisPad1+"px";
	var dOffset1=$(inner1).css("left");
	$("#"+id1+" .leftarrow").css({display:"none"});
	$("#"+id1+" .rightarrow").css({display:"block"});
	function setCarousel2(){
		$(inner1).stop();
	}
	function setCarousel3(){
		$("#"+id1+" .leftarrow,#"+id1+" .rightarrow").css({display:"block"});
	}
	$("#"+id1+" .rightarrow").mouseover(function(){
		if($$.isLoading1) return;
		var timing1=(inner1.offsetWidth-car1.offsetWidth)+inner1.offsetLeft;
		$(inner1).animate({left:"-"+(inner1.offsetWidth-car1.offsetWidth)+"px"},timing1,function(){$("#"+id1+" .rightarrow").css({display:"none"});});
		setCarousel3();
	});
	$("#"+id1+" .leftarrow").mouseover(function(){
		if($$.isLoading1) return;
		var timing1=-inner1.offsetLeft;
		$(inner1).animate({left:dOffset1},timing1,function(){$("#"+id1+" .leftarrow").css({display:"none"});});
		setCarousel3();
	});
	$("#"+id1+" .leftarrow,#"+id1+" .rightarrow").mouseout(setCarousel2);
	$("#"+id1+" .leftarrow,#"+id1+" .rightarrow").click(function(){return false;});
}

//calendar
function daysInMonth1(iMonth, iYear){
	return 32 - new Date(iYear, iMonth, 32).getDate();
}
function setCalendar1(op1){
	function setCalendar2(node1,el1,index1){
		parent.popup1Clean();
		parent.$$.getOffset1(el1);
		parent.$$.getOffset2(el1);
		parent.$("body").append('<div class="popup1" style="top:'+(parent.$$.vGetOffset1+el1.offsetHeight)+'px;left:'+(15+parent.$$.vGetOffset2)+'px;z-index:999999">'+$(node1).find(".c-mouseover")[index1].innerHTML+'</div>');
		parent.popup1Scan();
	}
	function setCalendar3(el1){
		var aDates1=el1.className.split("_");
		var aDates2=new Array();
		for(i=0;i<aDates1.length;i++){
			var tmp1=aDates1[i].split("-");
			if(tmp1[1]==(vDate1.getMonth()+1)&&tmp1[2]==vDate1.getFullYear()) {
				var tmp2={};
				if(tmp1[3]) {
					tmp2.ticketID=tmp1[3];
				}
				tmp2.day=tmp1[0]-1;
				aDates2.push(tmp2);
			}
		}
		var ticketLinks1=$(el1).find(".tickets-online-bcm");
		$(ticketLinks1).each(function(){ this.baseUrl1=this.href; });
		for(i=0;i<aDates2.length;i++){
			if(aDates2[i].ticketID) {
				$(ticketLinks1).each(function(){
					this.href=this.baseUrl1+"/"+aDates2[i].ticketID;
				});
			}
			parent.$("#"+op1.id+" .calendar-event")[aDates2[i].day].innerHTML+='<div class="calendar-event-item">'+el1.innerHTML+'</div>';
		}
	}
	var aMonths1=$("#months")[0].innerHTML.split("|");
	var oDays1=parent.$("#"+op1.id+" .calendar-days")[0];
	var aDays1=$("#days").html().split("|");
	var vCurrentDate1=new Date($("#date-current")[0].innerHTML);
	var vDate1=new Date($("#date")[0].innerHTML);
	var vDate2=new Date(vDate1.getFullYear(),vDate1.getMonth(),1);
	var vDate3=new Date(vDate1.getFullYear(),(vDate1.getMonth()-1),1);
	var vDate4=new Date(vDate1.getFullYear(),(vDate1.getMonth()+1),1);
	var oDate1=parent.$("#"+op1.id+" .nav-mid")[0];
	var oDate2=parent.$("#"+op1.id+" .nav-left")[0];
	var oDate3=parent.$("#"+op1.id+" .nav-right")[0];

	// oDate2.onclick=function(){
		// parent.$("#"+op1.id+"-source")[0].src=op1.source+"?"+(vDate3.getMonth()+1)+"/01/"+vDate3.getFullYear();
		// return false;
	// }
	// oDate3.onclick=function(){
		// parent.$("#"+op1.id+"-source")[0].src=op1.source+"?"+(vDate4.getMonth()+1)+"/01/"+vDate4.getFullYear();
		// return false;
	// }

	var vDummies1="";
	var vDummiesCount=vDate2.getDay();
	if(vDate2.getDay()==0) vDummiesCount=7;
	for(i=0;i<vDummiesCount-1;i++){
		vDummies1+='<div class="calendar-event-dummy"></div>';
	}
	var events1=parent.$("#"+op1.id+" .calendar-events")[0];
	var vEvents1="";
	var vEventsCount=daysInMonth1(vDate2.getMonth(),vDate2.getYear());
	for(i=0;i<vEventsCount;i++){
		vEvents1+='<div class="calendar-event"></div>';
	}
	events1.innerHTML=vDummies1+vEvents1;
	$("#events > div").each(function(){ setCalendar3(this); });
	
	oDate1.innerHTML=aMonths1[vDate2.getMonth()]+" "+vDate2.getFullYear();
	var aDays1tmp="";
	for(i=0;i<aDays1.length;i++){
		aDays1tmp+='<div class="calendar-day">'+aDays1[i]+'</div>';
	}
	oDays1.innerHTML=aDays1tmp;

	$(events1).find(".calendar-event").each(function(i){
		var eventDate1=new Date(vDate1.getFullYear(),vDate1.getMonth(),i+2);
		if(eventDate1.getDay()==0||eventDate1.getDay()==1) this.className+=" weekend-day";
		if(i+1==vCurrentDate1.getDate()&&vCurrentDate1.getMonth()==vDate1.getMonth()&&vCurrentDate1.getFullYear()==vDate1.getFullYear()) this.className+=" current-day";
		if(op1.autoDayNumbers) $(this).append('<a class="calendar-event-day" href="'+($(this).find(".calendar-event-day-href")[0]?$(this).addClass("event-day").find(".calendar-event-day-href")[0].href:"#d")+'">'+(i+1)+'</a>')[0];
		var itemCount1 = $(this).find(".calendar-event-item").each(function(){
			var eventNode1=this;
			if(op1.mouseoverPopup&&$(this).find(".c-link")[0]&&$(this).find(".c-mouseover")[0]){
				$(this).find(".c-link")[0].onmouseover=function(){ setCalendar2(eventNode1,this,0); };
			}
			if($(this).find("a")[0]&&$(this).find(".c-click")[0]){
				$(this).find("a")[0].onclick=function(){ parent.popup1Clean();parent.clickPopup1($(eventNode1).find(".c-click")[0]); return false; };
			}
			$(this).find("a").each(function(){
				this.onmouseout=function(){ parent.popup1Clean(); };
			});
		}).length;
		if(itemCount1==1) $(this).addClass("one-event");
		else if(itemCount1==2) $(this).addClass("two-events");
		else if(itemCount1>2) $(this).addClass("more-events");
	
		$(this).find(".calendar-event-item > a img").each(function(){
			this.imgCheck1=$$.imgCheck1;
			if(this.imgCheck1()) $(this).remove();
		});
		
	});
}

//remove image without source
$$.imgCheck1=function(){
	var itmp1=this.src.split(".");
	var itmp2=itmp1[itmp1.length-1];
	if(itmp2.indexOf("/")!=-1) return true;
	else return false;
}

//popups
function popup1Clean(){
	$(".popup1").remove();
	$$.vGetOffset1=0;
	$$.vGetOffset2=0;
}
$$.vGetOffset1=0;
$$.getOffset1=function(element1){
	$$.vGetOffset1+=element1.offsetTop;
	if(element1.offsetParent) $$.getOffset1(element1.offsetParent);
}
$$.vGetOffset2=0;
$$.getOffset2=function(element1){
	$$.vGetOffset2+=element1.offsetLeft;
	if(element1.offsetParent) $$.getOffset2(element1.offsetParent);
}
function popup1Scan(){
	$$.aPanscanPopTmp1=$(".popup1 .panscan");
	$($$.aPanscanPopTmp1).each(function(i){
		this.imgCheck1=$$.imgCheck1;
		if(this.imgCheck1()) $(this).css({display:"none"});
		this.PanscanPopTmp1=$$.Panscan1;
		this.imgLoad1=$$.imgLoad1;
		this.index1=i;
		this.method1="PanscanPopTmp";
		this.imgLoad1();
	});
}
function popup2Scan(){
	$$.aPanscanPop2Tmp1=$("#popup2 .panscan");
	$($$.aPanscanPop2Tmp1).each(function(i){
		this.PanscanPop2Tmp1=$$.Panscan1;
		this.imgLoad1=$$.imgLoad1;
		this.index1=i;
		this.method1="PanscanPop2Tmp";
		this.imgLoad1();
	});
}
function frame1Scan(){
	$$.aPanscanFrame1Tmp1=$("#carousel1 .panscan");
	$($$.aPanscanFrame1Tmp1).each(function(i){
		this.PanscanFrame1Tmp1=$$.Panscan1;
		this.imgLoad1=$$.imgLoad1;
		this.index1=i;
		this.method1="PanscanFrame1Tmp";
		this.imgLoad1();
	});
}
function frame2Scan(){
	$$.aPanscanFrame2Tmp1=$("#calendar1-container .panscan");
	$($$.aPanscanFrame2Tmp1).each(function(i){
		this.PanscanFrame2Tmp1=$$.Panscan1;
		this.imgLoad1=$$.imgLoad1;
		this.index1=i;
		this.method1="PanscanFrame2Tmp";
		this.imgLoad1();
	});
}
function clickPopup1(dSource){
	$("body").append('<div id="popup2bg" style="position:absolute;left:0;top:0;background-color:black;width:'+$(document).width()+'px;height:'+$(document).height()+'px;z-index:999998"></div><div id="popup2" style="position:absolute;z-index:999999;">'+dSource.innerHTML+'</div>');
	$("#popup2bg").css({opacity:0.5});
	var popup2=$("#popup2")[0];
	var offset1=$(document).scrollTop()+Math.round($(window).height()/2-popup2.offsetHeight/2);
	if(offset1<0) offset1=$(document).scrollTop()+20;
	var offset2=$(document).scrollLeft()+Math.round($(window).width()/2-popup2.offsetWidth/2);
	popup2.style.top=offset1+"px";
	popup2.style.left=offset2+"px";
	// RCG
	popup2.style.left="100px";
	offset1=offset1-100;
	if(offset1<0) offset1=100;
	popup2.style.top=offset1+"px";
	// FIN RCG
	$("#popup2 .popup-close,#popup2bg").click(function(){
		$("#popup2").remove();
		$("#popup2bg").remove();
		return false;
	});
	popup2Scan();
	if($("#popup2 .gallery-image1 img")[0]&&$("#popup2 .gallery-thumbs")[0]) {
		$("#popup2 .gallery-image1 img")[0].id="timage";
		$("#popup2 .gallery-thumbs")[0].id="ennav";
		$$.setGallery1({startIndex:0,isAnimated:true,targetID:"timage",containerID:"ennav",descriptionID:"photo-desc",loaderID:"ajax-loader1"});
	}
	$("#popup2 .popup-recommend").each(function(){
		this.onclick=function(){
			$("#popup2 .rec-to-friend").toggleClass("rec-to-friend-selected");
			$("#popup2 .popup-recommend").toggleClass("popup-recommend-selected");
			$("#popup2 .rec-to-friend .inp1").each(function(){this.onclick=$$.clearField1;});
			return false;
		}
		var parent1=$("#popup2")[0];
		var image1=$("#popup2 .popup2-photo")[0];
		if(image1.offsetWidth>$(window).width()) image1.style.width=($(window).width()-100)+"px";
		parent1.style.width=image1.offsetWidth+"px";
		$("#popup2bg").css({height:$(document).height()+20+"px"});
		parent1.style.left=($(document).scrollLeft()+Math.round($(window).width()/2-popup2.offsetWidth/2))+"px";
	});
}
function flashPopup1(num1)
{
	if(($("#flashLinks .popup-title")[num1]).innerHTML.toUpperCase().indexOf('HOTEL') > -1)
	{
		var fecha=new Date();
		var mm=fecha.getMonth();
		var yy=fecha.getFullYear();
		var dayIni=fecha.getDate()+1;
		var dayFin=dayIni+2;
		var fini=dayIni+"/"+mm+"/"+yy;
		var ffin=dayFin+"/"+mm+"/"+yy;
	
		self.location ='http://www.bcmplanetdance.com/en/hotel-reserva';
		//self.location ='http://www.bcmplanetdance.com/en/hotel-reserva?ad=2&ide=94&lang=&ni=0&fini=25/06/2010&ffin=28/06/2010&pr=paso1';
		//self.location = 'https://booking.kubikcrs.com/paso1.asp?ide=94&lang=en&pr=paso1&idEmpresa=94';
	}
	else
	{
		if($("#flashLinks li")[num1]) clickPopup1($("#flashLinks li")[num1]);
	}
}

// dropdown menu
$$.setMenu1=function(conId){
	var oCon=document.getElementById(conId);
	oCon.sett={
		time:setTimeout("",1)
	};
	var aItems=$("#"+conId+" .menuitem");
	$(aItems).each(function(i){
		this.index1=i;
		this.container=document.getElementById(conId);
		if($(this).find("div.menuchild")[0]) {
			this.mChild=$(this).find("div.menuchild")[0];
			this.mChild.offHeight=this.mChild.offsetHeight;
			this.getElementsByTagName("a")[0].onmouseover=function(){
				$("#"+conId+" div.menuchild").css({visibility:"hidden"});
				clearTimeout($("#"+conId)[0].sett.time);
				$(this.parentNode.mChild).css({visibility:"visible"});
				this.parentNode.mChild.style.left=this.parentNode.offsetLeft+"px";
				$(oCon).find(".selected2").each(function(){ $(this).removeClass("selected2"); });
				$(this.parentNode).addClass("selected2");
				if(this.parentNode.mChild.offsetWidth<this.offsetWidth) this.parentNode.mChild.style.width=this.parentNode.offsetWidth+"px";
				else $(this.parentNode.mChild).css({width:this.parentNode.mChild.offsetWidth+"px"});
				$(this.parentNode.mChild).find(".menu-bottom-wrap").css({width:(this.parentNode.mChild.offsetWidth-4)+"px"});
			};
			this.getElementsByTagName("a")[0].onmouseout=function(){
				clearTimeout($("#"+conId)[0].sett.time);
				$("#"+conId)[0].sett.time=setTimeout('$("#'+conId+' .menuitem").eq('+this.parentNode.index1+').removeClass("selected2").find("div.menuchild")[0].style.visibility="hidden"',500);
				if(oCon.lastSelected1=="undefined") oCon.lastSelected1=this;
				else {
					$(oCon.lastSelected1).removeClass("selected2");
					oCon.lastSelected1=this;
				}
			};
			this.mChild.onmouseover=function(){
				clearTimeout($("#"+conId)[0].sett.time);
			};
			this.mChild.onmouseout=function(){
				clearTimeout($("#"+conId)[0].sett.time);
				$("#"+conId)[0].sett.time=setTimeout('$("#'+conId+' .menuitem").eq('+this.parentNode.index1+').removeClass("selected2").find("div.menuchild")[0].style.visibility="hidden"',500);
			};
		}
	});
};

//player options from xml
function playerFunc1(p1){
	var song = parent.topFrame.song1;
	if(p1==1) {
		song.stop();
		parent.topFrame.isPlaying1=false;
	}
	if(p1==2) {
		song.play({onfinish: function() { this.play(); }});
		parent.topFrame.isPlaying1=true;
	}
	if(p1==3) {
		song.pause();
		parent.topFrame.isPlaying1=false;
	}
	if(p1==4) parent.topFrame.soundManager.setVolume("song1",song.volume==300?300:song.volume+20);
	if(p1==5) parent.topFrame.soundManager.setVolume("song1",song.volume==0?0:song.volume-20);
};

$(document).ready(function(){

$(".button *").hover(
	function(){ $(this).stop().animateToClass("button-state2",500); },
	function(){ $(this).stop().animateToClass("button-state1",500); }
);

if($("#ennav")[0]) $$.setGallery1({startIndex:0,isAnimated:true,targetID:"timage",containerID:"ennav",descriptionID:"photo-desc",loaderID:"ajax-loader1",hasTimer1:true,rememberHistory1:true});

if($("#mainmenu")[0]) $$.setMenu1("mainmenu");

$(".close").click(function(){this.parentNode.style.display="none"});

$$.bodyClass1=$("body")[0].className;

if($$.bodyClass1=="iframe"){
	if(parent.$("#calendar1-container")[0]) setCalendar1({id:"calendar1-container",source:"iframe1.html",mouseoverPopup:true,autoDayNumbers:true});
	if(parent.$("#calendar2-container")[0]) setCalendar1({id:"calendar2-container",source:"iframe2.html",mouseoverPopup:true,autoDayNumbers:true});
	if(parent.$("#calendar3-container")[0]) setCalendar1({id:"calendar3-container",source:"iframe5.html",mouseoverPopup:true,autoDayNumbers:true});
	parent.frame2Scan();
	if($("#carousel1-content")[0]) {
		parent.$$.isLoading1=false;
		setTimeout('parent.$("#carousel1-source")[0].src=parent.$("#carousel1-source")[0].src;parent.$$.isLoading1=true;',10000);
		parent.$("#carousel1 ul").css({left:"3px"}).stop();
		parent.$("#carousel1 ul")[0].innerHTML=$("#carousel1-content").html();
		parent.setCarousel1("carousel1");
		parent.frame1Scan();
		parent.$(".popup-container1 .box2").click(function(){
			if($(this).find(".first-click")[0]){
				parent.clickPopup1($(this).find(".first-click")[0]);
				return false;
			}
		});
	}
}

if($("#multimedia-gallery")[0]){
	$("#multimedia-gallery li").click(function(){
		if($(this).find(".data-source")[0]) {
			clickPopup1($(this).find(".data-source")[0]);
			return false;
		}
	});
}

$(".s2-checkbox1 .checkbox1").each(function(){
	var targetImg1=$(this).parent().parent().find(".s2-checkbox1-right img")[0];
	if(this.id=="cb-tickets"&&this.checked&&targetImg1.src.match(/ticket-plus1/)){
		targetImg1.src=targetImg1.src.replace(/ticket-plus1/,"ticket-plus2");
	}
	if(this.id=="cb-tickets-plus"&&this.checked&&targetImg1.src.match(/ticket-plus1/)){
		targetImg1.src=targetImg1.src.replace(/ticket-plus1/,"ticket-plus3");
	}
	this.onchange=function(){
		//alert($('#cb-tickets').checked);
		if(this.id=="cb-tickets"){
			if(this.checked){ 
				targetImg1.src=targetImg1.src.replace(/ticket-plus\d/,"ticket-plus2");
				$('.checktikets').removeClass('hidden1');
				$('#envio').hide();
			}else{
				targetImg1.src=targetImg1.src.replace(/ticket-plus\d/,"ticket-plus1");
				$('.checktikets').addClass('hidden1');
				$('#envio').hide();
			}
		}
		if(this.id=="cb-tickets-plus"){
			if(this.checked){
				targetImg1.src=targetImg1.src.replace(/ticket-plus\d/,"ticket-plus3");
				$('.checktikets').addClass('hidden1');
			    $('#envio').show();
				 
			}else{
				targetImg1.src=targetImg1.src.replace(/ticket-plus\d/,"ticket-plus1");
				$('.checktikets').addClass('hidden1');
			    $('#envio').hide();
			}
		}
	}
});

$("#events-parties .box2,#events-parties .box3").click(function(){
	if($(this).find(".first-click")[0]){
		clickPopup1($(this).find(".first-click")[0]);
		return false;
	}
});

});




function clickPopup21(dSource){
	$("body").append('<div id="popup2bg" style="position:absolute;left:0;top:0;background-color:black;width:'+$(document).width()+'px;height:'+$(document).height()+'px;z-index:999998"></div><div id="popupX" style="position:absolute;z-index:999999;">'+'<EMBED SRC="http://player.stickam.com/stickamPlayer/177703262-9590287" TYPE="application/x-shockwave-flash" wmode="transparent" WIDTH="480" HEIGHT="480" scale="noscale" allowScriptAccess="always" allowFullScreen="true" ALIGN="BOTTOM"></embed>'+'</div>');
	$("#popup2bg").css({opacity:0.5});
	var popup2=$("#popupX")[0];
	var offset1=$(document).scrollTop()+Math.round($(window).height()/2-popup2.offsetHeight/2);
	if(offset1<0) offset1=$(document).scrollTop()+20;
	var offset2=$(document).scrollLeft()+Math.round($(window).width()/2-popup2.offsetWidth/2);
	popup2.style.top=offset1+"px";
	popup2.style.left=offset2+"px";
	$("#popupX .popup-close,#popup2bg").click(function(){
		$("#popupX").remove();
		$("#popup2bg").remove();
		return false;
	});

}

function clickPopup212(dSource){
	$("body").append('<div id="popup2bg" style="position:absolute;left:0;top:0;background-color:black;width:'+$(document).width()+'px;height:'+$(document).height()+'px;z-index:999998"></div><div id="popupX" style="position:absolute;z-index:999999;">'+'<EMBED SRC="http://player.stickam.com/stickamPlayer/177703262-9590287" TYPE="application/x-shockwave-flash" wmode="transparent" WIDTH="480" HEIGHT="480" scale="noscale" allowScriptAccess="always" allowFullScreen="true" ALIGN="BOTTOM"></embed>'+'</div>');
	$("#popup2bg").css({opacity:0.5});
	var popup2=$("#popupX")[0];
	var offset1=$(document).scrollTop()+Math.round($(window).height()/2-popup2.offsetHeight/2);
	if(offset1<0) offset1=$(document).scrollTop()+20;
	var offset2=$(document).scrollLeft()+Math.round($(window).width()/2-popup2.offsetWidth/2);
	popup2.style.top=offset1+"px";
	popup2.style.left=offset2+"px";
	$("#popupX .popup-close,#popup2bg").click(function(){
		$("#popupX").remove();
		$("#popup2bg").remove();
		return false;
	});

}

$(document).ready(function(){
	$('.livecam').click(function(){
			clickPopup21();
			return false;
		}
	);
	// $('.terms-and-conditions').click(function(){
			// clickPopup212();
			// return false;
		// }
	// );
});
