 $(document).ready(function() {
	/*deprecated, see html document*/
	/*var daysOfMonth = new Array();
	daysOfMonth[1] = "Mar&#355;i"; daysOfMonth[2] = "Miercuri"; daysOfMonth[3] = "Joi"; daysOfMonth[4] = "Vineri"; daysOfMonth[5] = "S&acirc;mb&#259;t&#259;"; daysOfMonth[6] = "Duminic&#259;"; daysOfMonth[7] = "Luni";daysOfMonth[8] = "Mar&#355;i"; daysOfMonth[9] = "Miercuri"; daysOfMonth[10] = "Joi"; daysOfMonth[11] = "Vineri"; daysOfMonth[12] = "S&acirc;mb&#259;t&#259;"; daysOfMonth[13] = "Duminic&#259;"; daysOfMonth[14] = "Luni";daysOfMonth[15] = "Mar&#355;i"; daysOfMonth[16] = "Miercuri"; daysOfMonth[17] = "Joi"; daysOfMonth[18] = "Vineri"; daysOfMonth[19] = "S&acirc;mb&#259;t&#259;"; daysOfMonth[20] = "Duminic&#259;"; daysOfMonth[21] = "Luni";daysOfMonth[22] = "Mar&#355;i"; daysOfMonth[23] = "Miercuri"; daysOfMonth[24] = "Joi"; daysOfMonth[25] = "Vineri"; daysOfMonth[26] = "S&acirc;mb&#259;t&#259;"; daysOfMonth[27] = "Duminic&#259;"; daysOfMonth[28] = "Luni";daysOfMonth[29] = "Mar&#355;i"; daysOfMonth[30] = "Miercuri";*/
			
	$('table.programtv .row-info').hide();		
	$('table.programtv .row-title').mouseover(function(){
		$(this).css({'cursor': 'pointer'});
		//$(this).find('td').css ({'background': '#fdfdfb url(assets/images/row-title.gif) repeat-x left bottom', 'color': '#561f5d'})
		$(this).addClass('hovered');
	}).mouseout(function(){
		$(this).removeClass('hovered');
	});
	
	$('table.programtv .row-title').each(function(i){
		$(this).click(function(){
			$('table.programtv .row-info').hide();
			$('table.programtv .row-title').each(function(m){
				if(m!=i) $(this).removeClass("expanded");
				if(m!=i) $(this).addClass("collapsed");				
			});
			
			$(this).removeClass('hovered');
			if($(this).hasClass("expanded")){
				$(this).removeClass("expanded");
				$(this).removeClass("on");
				$(this).addClass("collapsed");
				$(this).next('.row-info').hide();
			}else{
				$(this).addClass("expanded");
				$(this).addClass("on");
				$(this).removeClass("collapsed");
				$(this).next('.row-info').show();
			}
		})
	});



	
	//attach day events
	$(".day-navigation-active").mousemove(function(evt){
		var mousePos = evt.pageX-($(".day-navigation-active").position().left);
		var dayCalculate = Math.ceil(mousePos/28);
		
		if(dayCalculate<10) dayCalculate2 = "0"+dayCalculate;
		else dayCalculate2 = dayCalculate;
		
		if (dayCalculate<=finishDay){ 
		  positionTip(dayCalculate, daysOfMonth[dayCalculate]+" "+dayCalculate2+"."+positionDateFormat);
		}
	});

	$("body#program-cinestar .day-navigation-active").click(function(evt){
		var mousePos = evt.pageX-($("body#program-cinestar .day-navigation-active").position().left);
		var dayCalculate = Math.ceil(mousePos/28);
		if (dayCalculate<=finishDay){
			if(dayCalculate<10) dayCalculate = "0"+dayCalculate;
				document.location.href = "cs_"+dayCalculate+fileDateFormat +".html";
		}
	});
	
	$("body#program-comedystar .day-navigation-active").click(function(evt){
		var mousePos = evt.pageX-($("body#program-comedystar .day-navigation-active").position().left);
		var dayCalculate = Math.ceil(mousePos/28);
		if (dayCalculate<=finishDay){
			if(dayCalculate<10) dayCalculate = "0"+dayCalculate;
				document.location.href = "co_"+dayCalculate+fileDateFormat +".html";
		}
		});
	
	$("body#program-actionstar .day-navigation-active").click(function(evt){
		var mousePos = evt.pageX-($("body#program-actionstar .day-navigation-active").position().left);
		var dayCalculate = Math.ceil(mousePos/28);
		if (dayCalculate<=finishDay){
			if(dayCalculate<10) dayCalculate = "0"+dayCalculate;
				document.location.href = "as_"+dayCalculate+fileDateFormat +".html";
		}
	});
	
	if(curentDay<10) curentDay2 = "0"+curentDay;
	else curentDay2 = curentDay;
	
	$(".day-navigation-active").mouseout(function(evt){
		positionTip(curentDay,daysOfMonth[curentDay]+" "+curentDay2+"."+positionDateFormat);
	});
	
	enableDay(startDay);
	enableStars(daysInMonth);
	
	positionTip(curentDay,daysOfMonth[curentDay]+" "+curentDay2+"."+positionDateFormat);
	
	//update home links
	
	var curentDate = new Date();
	//var curentDay = curentDate.getDate();
	//var curentMonth = curentDate.getMonth()+1;
	
	
	prevDay = curentDay-1;
	prevWeekDay = prevDay;
	
	if(prevDay<1) {
		prevDay = daysPrevMonth;
		prevMonth = curentMonth-1; 
		if (prevMonth<10) prevMonth = "0"+prevMonth;
		if(prevMonth < 1){
			prevMonth = 12;
		}
		positionDateFormatPrev = prevMonth+"."+curentDate.getFullYear();
		fileDateFormatPrev = prevMonth + "" + curentDate.getFullYear();
	}
	else {
		positionDateFormatPrev = positionDateFormat;
		fileDateFormatPrev = fileDateFormat;
	}
	
	
	//alert("Prev: "+prevWeekDay);
	if(prevDay<10) prevDay = "0"+prevDay;
	
	nextDay = curentDay+1;
	nextWeekDay = nextDay;
	nextYear = curentDate.getFullYear();
	
	if(nextDay>daysInMonth) {
		nextDay = 1;
		nextMonth = curentMonth+1; 
		if (nextMonth<10) nextMonth = "0"+nextMonth;
		if(nextMonth > 12) {
			nextMonth = "01";
			nextYear = nextYear+1;
		}
		positionDateFormatNext = nextMonth + "." +  nextYear;
		fileDateFormatNext = nextMonth + '' + nextYear;
	}
	else {
		positionDateFormatNext = positionDateFormat;
		fileDateFormatNext = fileDateFormat;
	}
 	
 	
	//alert("Next: "+nextWeekDay);
	if(nextDay<10) nextDay = "0"+nextDay;
	
	if(curentMonth<10) curentMonth = "0"+curentMonth;
	
	var fileName = curentDay+""+curentMonth+""+curentDate.getFullYear();
	
	$('.cinestarlink_1').attr('href',"cs_"+fileName+".html");
	$('.cinestarlink_2').attr('href',"co_"+fileName+".html");
	$('.cinestarlink_3').attr('href',"as_"+fileName+".html");

	//Adaugare spatiu gol pentru audienta generala
	$('td.target span').each(function(i) {
		if ($(this).html() == " ") $(this).html('&nbsp;')
	});

	if( $('#program-actionstar').size() ) {
		$('#nav-prev a').html( daysOfMonth[prevWeekDay]+" "+(prevDay)+"."+positionDateFormatPrev).attr('href',"as_"+(prevDay)+fileDateFormatPrev+".html");
		$('#nav-next a').html( daysOfMonth[nextWeekDay]+" "+(nextDay)+"."+positionDateFormatNext).attr('href',"as_"+(nextDay)+fileDateFormatNext+".html");
	}
	
	if( $('#program-comedystar').size() ) {
		$('#nav-prev a').html( daysOfMonth[prevWeekDay]+" "+(prevDay)+"."+positionDateFormatPrev).attr('href',"co_"+(prevDay)+fileDateFormatPrev+".html");
		$('#nav-next a').html( daysOfMonth[nextWeekDay]+" "+(nextDay)+"."+positionDateFormatNext).attr('href',"co_"+(nextDay)+fileDateFormatNext+".html");
	}
	
	if( $('#program-cinestar').size() ) {
		$('#nav-prev a').html( daysOfMonth[prevWeekDay]+" "+(prevDay)+"."+positionDateFormatPrev).attr('href',"cs_"+(prevDay)+fileDateFormatPrev+".html");
		$('#nav-next a').html( daysOfMonth[nextWeekDay]+" "+(nextDay)+"."+positionDateFormatNext).attr('href',"cs_"+(nextDay)+fileDateFormatNext+".html");
	}
	
	
}); 

//var daysInMonth = 31;

function positionTip(dayNumber, stringDate){
	$("#currentDate").html(stringDate);
	//dayPercent = (dayNumber*100/daysInMonth);
	dayPercent = (dayNumber*100/31);
	var toolTipPosition = Math.ceil(7.15*dayPercent)-25;
	$(".day-tip").css({'margin-left':toolTipPosition+"px"});
	var toolTipColtPosition = Math.round(1.5*dayPercent)+5;
	$(".day-tip .date b").css({'background-position':toolTipColtPosition+"px 100%"});
}

function enableDay(dayNumber){
	$(".day-navigation-inactive").css({'width':((dayNumber-1)*28)+"px"});
}

function enableStars(dayNumber){
	$(".day-navigation-active").css({'width':((dayNumber)*28)+"px"});
}
