jQuery(document).ready(function() {

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~ Inits ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	initMPH();
	initCalendar300();
});

/**
 *
 * @access public
 * @return void
 **/
function calcItemHeights(carousel){
	// Work out the height of the biggest LI to put set the height of the clip div.
	var maxHeight = 0;
	jQuery('li',carousel.list).each(function(index, element){
		if(jQuery(element).height() > maxHeight){
			maxHeight = jQuery(element).outerHeight(true);
		}
	});
	carousel.clip.height(maxHeight);

	if(jQuery('li',carousel.list).length <= 4){
		jQuery(carousel.buttonNext).hide();
		jQuery(carousel.buttonPrev).hide();
	}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~ MPH ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function initMPH()
{
	jQuery('.gallery_slideshow').each(function(index,element){

		var container = jQuery(element).parent();
		var carousel = false;
		// If we have thumbnails
		if(jQuery(element).siblings('ul.gallery_thumbs').length >0 ){

			carousel = jQuery(element).siblings('ul.gallery_thumbs').jcarousel({
				scroll: 1,
				wrap: "none",
				itemFallbackDimension: 107,
				initCallback: calcItemHeights
			});
			carousel.find('li a.image').click(function(e){
				e.preventDefault(); // Don't prevent the default because we want it to link to the image now...

				slide_id = parseInt(jQuery("li:eq("+jQuery(this).parents('li').attr("rel")+")",element).index());

				jQuery(element).anythingSlider(slide_id + 1);
				jQuery('.playVideoyt, .playVideobuto, .playVideovim, .playVideoflv',element).each(function(){
					jQuery(this).html('');
				});
				jQuery(this).parent().siblings().removeClass('active');
				jQuery(this).parent().addClass('active');
				thumbCounter = null;
			});

		}

		var showNav = true;

		// If we don't want the nav
		if(jQuery(element).hasClass('no_nav')){
			showNav = false;
		}

		// If there are some images
		if (jQuery('li',element).size() > 0)
		{
			jQuery(element).anythingSlider({
				animationTime : 0,
				buildNavigation: showNav,
				autoPlay:true,
				playerColor: '<?=$player_color?>',
				delay:10000
			})
			.anythingSliderFx({
			  '.panel' : [ 'fade', 5000, 'easeOutCirc' ] // target the entire panel and fade will take 1000ms
			 })
			.bind('slide_complete',function(e,base){

				// If we have a carousel, move it along.
			 	if(carousel){
			 		carousel.find('li').removeClass('active').eq(base.currentPage-1).addClass('active');

			 		carousel.jcarousel('scroll',base.currentPage-1);
			 	}
			});


		}

	});

	jQuery('.gallery_slideshow').show();

	jQuery('.anythingWindow').live( 'mouseenter',  function() {
		jQuery(this).parent().find('span.back').css({'left':'0px'});
		jQuery(this).parent().find('span.forward').css({'right':'0px'});
	});

	jQuery('.anythingWindow').live( 'mouseleave',  function() {
		jQuery(this).parent().find('span.back').css({'left':'-60px'});
		jQuery(this).parent().find('span.forward').css({'right':'-60px'});
	});

	jQuery('.arrow').live( 'mouseenter',  function() {
		jQuery(this).parent().find('span.back').css({'left':'0px'});
		jQuery(this).parent().find('span.forward').css({'right':'0px'});
	});

   jQuery('.arrow').live( 'mouseleave',  function() {
		jQuery(this).parent().find('span.back').css({'left':'-60px'});
		jQuery(this).parent().find('span.forward').css({'right':'-60px'});
    });

}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~ Calendar ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function initCalendar300()
{

	jQuery(".calendar_date, .datepicker").datepicker('destroy');
	jQuery(".calendar_date, .datepicker").datepicker({
		dayNamesMin: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
		firstDay: 1,
		dateFormat: 'dd/mm/yy',
		beforeShowDay: function (date) {
			var _return = false;
			jQuery.each(calendarEvents, function(key, event_date) {
				if(date.getDate() == event_date[0] && date.getMonth() == event_date[1] && date.getFullYear() == event_date[2])
				{
					_return = true;
				}
			});
			if(_return)
			{
				return [true,"ui-state-event",date.getDate()];
			}
			else
			{
				return [true,"ui-state-full",date.getDate()];
			}
		},
		onSelect: function(date, inst) {
			if(inst.id.substr(0, 2) == 'dp'){

				var url = '/entertainment/page/1?from_date=' + escape(date) + '&to_date=' + escape(date);



				if (typeof calendarCountry !== "undefined")
				{
					url = url + '&country='+calendarCountry;
				}

				if (typeof calendarEventType !== "undefined")
				{
					url = url + '&event_type='+calendarEventType;
				}

				window.location = url;
			} else {
				jQuery('#'+inst.id).parent().parent().parent().parent().find('.input_select_value span').html(': '+date).parent().parent().find('.input_select_options').addClass('displaynone');
			}
		},
		onChangeMonthYear: function (yr, mon, inst){
			if(this.id.substr(0, 2) == 'dp'){
				var picker = jQuery(this);

				var myData = {"month": mon, "year": yr};


				if (typeof calendarCountry !== "undefined")
				{
					myData.country=calendarCountry;
				}

				if (typeof calendarEventType !== "undefined")
				{
					myData.event_type=calendarEventType;
				}


				jQuery.getJSON('/home/getDatesForCalendar', myData, function (data){
					calendarEvents = data;
					picker.datepicker('refresh');
					setTimeout("fixDays();", 1);
				});
			}
		}
	});
	setTimeout("fixDays();", 1);
}

function fixDays()
{
	jQuery('.hasDatepicker').each(function(i) {
		i += 1;
		jQuery(this).find('td:not(.ui-state-disabled)').each(function(k, day) {
			k += 1;
			day = jQuery(day);
			a = day.find('a');
			_a = a;
			a.remove();
			day.append('<div id="day_'+i+'_'+k+'"></div>');
			jQuery('#day_'+i+'_'+k).append(_a);
		});
	});
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~ Tab Set ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function initTabSet()
{
	jQuery('.tabs').tabs();
}


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~ Blank so you can cp ~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
