var featurePause = false;
var currentSlide = 0;
var markedEvents = {};

var markEvents = function($td, thisDate, month, year)
{
	if (markedEvents[thisDate.getFullYear().toString() + thisDate.getMonth().toString() + thisDate.getDate().toString()]) {
		$td.addClass('marked-event');
	}
}

function onBefore(curr, next, opts) { 
	var index = $(this).parent().children().index(this);
	currentSlide = index;
	if(featurePause) {
		$("ul.navigation-features").css({backgroundImage: 'url('+imagepath+'feature-buttons/'+(index+1)+'_play.gif)'});
	} else {
		$("ul.navigation-features").css({backgroundImage: 'url('+imagepath+'feature-buttons/'+(index+1)+'_pause.gif)'});
	}
}

$(document).ready(function(){
	
	img1 = new Image();
	img1.src = imagepath+'bg-'+section+'-tabs-clo-on.png';
	img2 = new Image();
	img2.src = imagepath+'bg-'+section+'-tabs-education-on.png';
	img3 = new Image();
	img3.src = imagepath+'bg-'+section+'-tabs-cabaret-on.png';
	
	if($.browser.msie && parseInt($.browser.version) == 6) {
		
		$("div.feature-text").css("margin-top","0");
		$("div.feature-text h2").css("font-size","12px");
		$("div.feature-text p").css("font-size","11px");
		$("div.feature-text p").css("line-height","14px");
		
		$("img.feature-frame").each(function(i){
			var url = $(this).css('background-image').replace('url("','');
			url = url.replace('")','');
			var newimage = '<img src="'+url+'" alt="'+$(this).attr("alt")+'" style="width: 410px;height: 220px;padding: 10px 0 0 16px;" />';
			$(this).replaceWith(newimage);
		});

	} else {
		
		$("img.whatsnew-image").each(function(i){
			$(this).css('width','auto');
			$(this).css('height','auto');
		});
		
	}
	
	$(document).pngFix();
	
	$("ul.navigation-primary").superfish();
	
	$("table.table-info tr:even td").css("background-color", "#FDEFDE");
	
	$("ul.navigation-primary ul li a").hover(
	  function () {
		var li = $(this).parent();
		$(li.children("a")).css({backgroundImage: 'url('+imagepath+'bg-nav-primary-item-on.gif)'});
	  },
	  function () {
		var li = $(this).parent();
		$(li.children("a")).css({background: 'none'});
	  }
	);
	
	$("ul.navigation-tabs a").hover(
	  function () {
		if(!$.browser.msie || ($.browser.msie && parseInt($.browser.version) == 7)) {
			var id = $(this).attr('id');
			var ul = $(this).parent().parent();
			if(id=='clo') {
				ul.css({backgroundImage: 'url('+imagepath+'bg-'+section+'-tabs-clo-on.png)'});
			} else if(id=='education') {
				ul.css({backgroundImage: 'url('+imagepath+'bg-'+section+'-tabs-education-on.png)'});
			} else if(id=='cabaret') {
				ul.css({backgroundImage: 'url('+imagepath+'bg-'+section+'-tabs-cabaret-on.png)'});
			}
		}
	  },
	  function () {
		if(!$.browser.msie || ($.browser.msie && parseInt($.browser.version) == 7)) {
			var id = $(this).attr('id');
			var ul = $(this).parent().parent();
			ul.css({backgroundImage: 'url('+imagepath+'bg-'+section+'-tabs-'+section+'-on.png)'});
		}
	  }
	);
	
	$("img.rollover").hover(
	  function () {
		$(this).attr('src', $(this).attr('src').replace('_off','_on') );
	  },
	  function () {
		$(this).attr('src', $(this).attr('src').replace('_on','_off') );
	  }
	);
	
	if(section == 'education') {
		$("ul.navigation-primary li.last ul").css({left: '3px'});
	} else {
		$("ul.navigation-primary li.last ul").css({left: '-28px'});
	}
	
	$("ul.navigation-features li a:last").css({width: '84px'});
	
	$('#q').focus(function(){
	  if($(this).val() == 'Search Our Site') {
		  $(this).attr('value','');
	  }
	});
	$('#q').blur(function(){
	  if($(this).val() == '') {
		  $(this).val('Search Our Site');
	  }
	});
	
	$('.eventCategorySelect').change(function(){
	  var title = $(this).attr('title');
	  var name = $(this).attr('name');
	  window.location.href = "/events/search/d:" + title + "/category:" + $(this).children("[@selected]").val() + "/section:" + name; 
	});
	
	$('.feature-rotation').cycle({ 
        fx:    'fade', 
        speed:  500,
        timeout:  4000,
		startingSlide: 0, 
    	before: onBefore
    });
	
	$('.navigation-features a').click(function(){
	  var index = $('.navigation-features a').index(this);
	  var slideCount = ($(this).parent().parent().children().length - 1);
	  if(index < slideCount) {
			  $('.feature-rotation').cycle(index);
			  if(!featurePause) {
				  featurePause = true;
				  $('.feature-rotation').cycle('pause');
				  $("ul.navigation-features").css({backgroundImage: 'url("'+imagepath+'feature-buttons/'+(index+1)+'_play.gif")'});
			  }
	 } else {
			  if(featurePause) {
				  featurePause = false;
				  $('.feature-rotation').cycle('resume');
				  $("ul.navigation-features").css({backgroundImage: 'url("'+imagepath+'feature-buttons/'+(currentSlide+1)+'_pause.gif")'});
			  } else {
				  featurePause = true;
				  $('.feature-rotation').cycle('pause');
				  $("ul.navigation-features").css({backgroundImage: 'url("'+imagepath+'feature-buttons/'+(currentSlide+1)+'_play.gif")'});
			  }
	  }
	  return false;
	});
	
});