// JavaScript Document

function imageSwapLink ( theLink, theTitle ) {
	
	//alert(theLink);
	
	var homeSwapperMoreInfo = document.getElementById('homeSwapperMoreInfo');
	homeSwapperMoreInfo.href = theLink;
	homeSwapperMoreInfo.title = theTitle;
	/*var homeSwapperBookNow = document.getElementById('homeSwapperBookNow');
	homeSwapperBookNow.href = theLink;*/
}


function doClearField ( inputField ) {
	var theField = document.getElementById(inputField);
	if (theField.value.substring(0,5).toLowerCase()=="enter" || theField.value.substring(0,6).toLowerCase()=="please") theField.value = '';
}

function resetFields ( element1, element2, element3 ) {
	
	var theElement1 = document.getElementById(element1);
	theElement1.value = '';
	var theElement2 = document.getElementById(element2);
	theElement2.value = '';
	
	var theElement3 = document.getElementById(element3);
	theElement3.value = '';
}



function toggle ( id, hideWords ) {

	var theSpanElement = document.getElementById('hideShow'+id).style.display;
	var linkImg = '';
	var style;
	var dotsStyle;

	if (theSpanElement == 'none' || !theSpanElement) {
		style = 'inline';
		dotsStyle = 'none';
		linkImg = 'pinkClose';
	} else {
		style = 'none';
		dotsStyle = 'inline';
		linkImg = 'pinkReadMore';
	}

	document.getElementById('hideShow'+id).style.display = style;
	document.getElementById('theDots'+id).style.display = dotsStyle;
	document.getElementById('bioOpenClose'+id).src = '/imgs/'+linkImg+'.gif';
	
}


/*------------------- CALENDAR AJAX ------------------------------*/
function regLinks ( $loadedData ) {
	
	$(".prevNext a",$loadedData).unbind("click").click(function() {
		
		var $path = $(this).attr("href");
	
		$path = $path.split("&");
		var $pid = $path[0].split("=");
		var $month = $path[1].split("=");
		
		$.get("/calendar.inc.php",

      	{pid: $pid[1], month: $month[1]},

      	function(data) {
			var $regCol = $("#calendar");
			$regCol.html(data);
			regLinks( $regCol );
      	});

		return false;

	});
	
}



$(document).ready(function(){
	
	/*$(".prevNext a").unbind("click").click(function() {
		
		var $path = $(this).attr("href");
		
		$path = $path.split("&");
		var $pid = $path[0].split("=");
		var $month = $path[1].split("="); 
		
		$.get("/calendar.inc.php",
		
      	{pid: $pid[1], month: $month[1]},

      	function(data) {
			var $regCol = $("#calendar");
			$regCol.html(data);
			regLinks( $regCol );
			
      	});

		return false;
	});
	*/
	
	// CALENDAR PREVIEW START
	var $calendarPreview = $("#calendarPreview");
	var $home = $("body").attr("class").split(" ");

	
	$("#calendar table a").hoverIntent(function(){
	
		var $calendarBox = ($(this).parent().parent().parent().parent().parent().parent().parent());
		
		var $pathCalendar = $(this).attr("href");
		
		//alert($pathCalendar);
		
		$pathCalendar = $pathCalendar.split("&");
		var $pid = $pathCalendar[0].split("=");
		var $dtPreview = $pathCalendar[1].split("=");
		$dtPreview = $dtPreview[1].split("%7C");
		$day = parseInt($dtPreview[0]);
		$month = $dtPreview[1];
		$year = parseInt($dtPreview[2]);
		
		
		$.get("/calendarPreview.inc.php",
		
      	{pid: $pid[1], day:$day ,month: $month, year:$year},

      	function(data) {
			$calendarPreview.html(data);
			
			var calBoxPosition = $calendarBox.position();
			var $marginTop = parseInt($calendarBox.css("margin-top").split("px"));
			
			$calendarPreview.css("top",calBoxPosition.top+$marginTop);
			$calendarPreview.css("left",calBoxPosition.left-355);	
			
			// DIRTY HACK FOR I6 TO FIX THE SEARCH BOX OVERLAY
			
			jQuery.each(jQuery.browser, function(i) {
 			 if($.browser.msie && $home[0] == 'homepage'){
    			$(".searchBox select").hide();
			 }
			});
			// END HACK IE6
			
			//$calendarPreview.show();
			$calendarPreview.animate({ opacity: 'show'});
      	});

		return false;
	},
		function () { }
    );

	if($home[0] == 'homepage') {
		$(".newsletterBox").mouseover(function(){
			$calendarPreview.animate({ opacity: 'hide'});
			 $(".searchBox select").show();
 		});
		$(".blockWrap").mouseover(function(){
			$calendarPreview.animate({ opacity: 'hide'});
			 $(".searchBox select").show();
 		});
		
	} else {
		$("#content").mouseover(function(){
			$calendarPreview.animate({ opacity: 'hide'});
			 $(".searchBox select").show();
 		});	
	}
	
	 $calendarPreview.hoverIntent(
      function () {
        $calendarPreview.show();	
      }, 
      function () {
       $calendarPreview.hide();
	   $(".searchBox select").show();
      }
    );


	
	// CALENDAR PREVIEW END
	
	
	
	// hides the slickbox as soon as the DOM is ready
	// (a little sooner than page load)
	$('.toggleHide').hide();
	// then toggles the slickbox on clicking the noted link
	$('a.slick-toggle').click(function() {

		$(this).next('.toggleHide').slideToggle(400);
		
		if($(this).html() == 'Close News') {
			$(this).html("Click to read the news");
		} else {
			//$(this).html('Close News');
		}
		
		return false;
	});
	
	
	/************ Transition Gallery ************/
	$("#transitionGallery").transition({
			displayTime: 8000,
			transitionTime: 500,
			autoRun: false,
			displayTitle: false,
			width: 432,
			height: 295,
			noBox: true,
			thumbSize: 125
	});
	
	
});


