document.write('<link rel="StyleSheet" href="/baileyRobinsonAssets/css/baileyRobinsonJavascript.css" type="text/css" media="screen" />');

/********************************************************************************
 
Name:     fnConfig
Function: main configuration function. sets up all functions to be called onLoad
 
*********************************************************************************/

function fnConfig() {
	fnSetDefaultSelected();
}

/********************************************************************************
 
Name:     jQuery
Function: jQuery on DOM ready function
 
*********************************************************************************/

var tabs = 3;
var count = 1;
var interval = 10;

$(function() {
  fnSearchBox();
  fnOffers();
  fnHomeFeature();
  
  $("#homepage #featureArea").everyTime(interval*500, function(i) {
    fnChangeTab();
  });

});



/********************************************************************************
 
Name:     Flash plugin detect
 
*********************************************************************************/
var flashdetect = false;
function fnFlashDetect() {
 if (navigator.plugins && navigator.plugins.length) {
  for (x=0; x < navigator.plugins.length; x++) {
   if (navigator.plugins[x].name.indexOf('Shockwave Flash') != -1) {
     flashdetect = true;      
    break;
   }
  }
 }
 else if (window.ActiveXObject) {
  for (x = 2; x <= 20; x++) {
   try {
    oFlash = eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash." + x + "');");
    if(oFlash) {
     flashdetect = true;  
    }
   }
   catch(e) {}
  }
 }
}
fnFlashDetect(); // run on file load; 



	
/********************************************************************************
 
Name:     Flash embed
Description:  Writeout flash code. Fixes Eolas update for IE as well.
@param swf  String path to swf file
@param width     Number value of movie width
@param height    Number value of movie height
@param alternateContent String of HTML to be served if flash is not installed
 
*********************************************************************************/
 
flash = new Object();
flash.insert = function(swf,width,height) {
	swf = swf.replace(/\./g,"%2E") // encode periods as %2e	
 if(flashdetect) {
 	flashObject = '<embed src="'+swf+'" menu="false" quality="high" width="'+width+'px" height="'+height+'px" type="application/x-shockwave-flash" wmode="transparent" salign="T" pluginspage="http://www.macromedia.com/go/getflashplayer" />'
 	document.write(flashObject);
 } else {
  	//flashObject = alternateContent;
	fnShowNoFlash();
 }
 
 
}

function fnShowNoFlash() {
	if (document.getElementById("noFlashContent")) {
		document.getElementById("noFlashContent").style.display = "block";
	}
	if (document.getElementById("noFlashContent1")) {
		document.getElementById("noFlashContent1").style.display = "block";
	}
	if (document.getElementById("noFlashContent2")) {
		document.getElementById("noFlashContent2").style.display = "block";
	}
	if (document.getElementById("noFlashContent3")) {
		document.getElementById("noFlashContent3").style.display = "block";
	}
	if (document.getElementById("noFlashContent4")) {
		document.getElementById("noFlashContent4").style.display = "block";
	}		
}



/********************************************************************************
 
Name:     DestinationsShowHide
Description:  Takes link url on thumbnails and shows this image within the page.  
Sets transparency of thumbnails once selected.
@param targ:     path to full size image

*********************************************************************************/

function fnDestinationsShowHide(targ) {

	document.getElementById("headerShowHide").getElementsByTagName("img")[0].src = targ.href;	
	document.getElementById("headerShowHide").getElementsByTagName("img")[0].alt = targ.getElementsByTagName("IMG")[0].alt;	
	
	var anchors = document.getElementById("shThumbnails").getElementsByTagName("A");

	if (document.all) {
		for (i=0;i<anchors.length;i++) {
			targ.parentNode.parentNode.getElementsByTagName("IMG")[i].style.filter = "alpha(opacity=100)";		
			}	
		targ.getElementsByTagName("IMG")[0].style.filter = "alpha(opacity=50)";
		}
	else {
		for (i=0;i<anchors.length;i++) {
			targ.parentNode.parentNode.getElementsByTagName("IMG")[i].style.opacity = "1";			
			}	
		targ.getElementsByTagName("IMG")[0].style.opacity = "0.5";
		}
	}
	


	
/********************************************************************************
 
Name:     		fnSetDefaultSelected
Description: 	Sets the default selected state on itinerary nav on first item 
				in nav list - wont get set for non-js users so they can browse
				the standard anchor list

*********************************************************************************/	

function fnSetDefaultSelected() {
	if(document.getElementById("itineryNavList")) {
		var listItems = document.getElementById("itineryNavList").getElementsByTagName("LI");
		listItems[0].className = "selected";
	}
}
	



/********************************************************************************
 
Name:     		fnSelectMe
Description: 	Sets class "selected" on the LI in the itinerary nav list that is 
				clicked on

*********************************************************************************/	
function fnSelectMe(obj) {
	var listItems = document.getElementById("itineryNavList").getElementsByTagName("LI");
	
	for (i=0;i<listItems.length;i++) {
		listItems[i].className = "";
	}	
	
	obj.parentNode.className = "selected";
}


	
/********************************************************************************
 
Name:     		fnItineraryShowHide
Description: 	Show / Hide the itinerary tabbed content.  Anchor contains link to ID 
				of element to show/hide.  JS tales the url, splits string to get ID 
				after the "#", and uses this ID to target element to show/hide.

*********************************************************************************/	
	
function fnItinerarySH(targ) {
	
	var itDetails = document.getElementById("itDetailWrapper").getElementsByTagName("DIV");
	
	for (i=0;i<itDetails.length;i++) { /* Loop through to hide all items */
		itDetails[i].style.display = "none";	
		}	
	
	var showItem = targ.href.split("#")[1];	/* Get ID from link */
	document.getElementById(showItem).style.display = "block";	
	
	}		
	
	
	

	
/********************************************************************************
 
Name:     fnPopup
 
*********************************************************************************/
function fnPopup(sUrl, scrollbars) {	
	if (!scrollbars) {
		scrollbars = "yes";
	}
	var iWidth = 360;
	var iHeight = 350;
	var sScreenX = screen.width;
	var sScreenY = screen.height;
	var x = sScreenX - iWidth;
	var y = sScreenY - iHeight;
	var winLeft = x/2;
	var winTop =  y/2;	
	window.open(sUrl,"","width=" + iWidth + ",height="+ iHeight + ",scrollbars="+scrollbars+",left=" + winLeft + ",top=" + winTop + ",resizable=yes");	
}


/********************************************************************************
 
Name:     fnPopUpStyle
 
*********************************************************************************/
function fnPopUpStyle(filePath, popUpStyle, attributes) {
	var width = 0;
	var height = 0;
	var sScreenX = screen.width
	var sScreenY = screen.height

	switch (popUpStyle){
		case "1" : 
			width = "600";
			height = "400";
			break;
		case "2":
			width = "412";
			height = "400";
			break;			
		case "3" :
			width = "620";
			height = "420";
			break;
		case "4" :
			width = "420";
			height = "297";
			break;			
		case "5" :
			width = "780";
			height = "540";
			break;			
			
	}

	var x = sScreenX - width
	var y = sScreenY - height
	var winLeft = x/2
	var winTop =  y/2 
	
	
	window.open(filePath,"","width=" + width + ",height=" + height + "," + attributes + ",left=" + winLeft + ",top=" + winTop)

}	



/* print function */
function fnPrint() {
	window.print();	
}

/********************************************************************************
Name:     fnSearchBox
*********************************************************************************/
function fnSearchBox(){
	
	sb = $('#searchForm input:text');
	id = sb.attr('id');
	label = $("#searchForm label[for='"+id+"']");
	
	label.hide();
	sb[0].defaultValue = label.text();
	sb.attr('value',label.text())
	
	sb.unbind("focus,blur").focus(function () {		
		if ($(this).val() == $(this)[0].defaultValue) {
        	$(this).val("");
        }
	 }).blur(function() {
        if ($(this).val() == "") {
        	$(this).val($(this)[0].defaultValue);
     	}
	 });

}

/********************************************************************************
Name:     fnOffers
*********************************************************************************/
function fnOffers(){
	if($('#offersBlock').length>0){
    	block = $('#offersBlock');
		$('div.offerSect',block).each(function(i){
			obj = $(this);
			title = $('div.offerTitle',obj);
			list = $('div.thumbNailList',obj);
			
			if(obj.hasClass('open')){
				list.show();
			} else {
				list.hide();
				obj.addClass('closed');
			}
			
			//setup click
			
			title.bind('click',function(){
				par = $(this).parents('div.offerSect');
				
				if(par.hasClass('closed')){
					//open it
					$(this).next('div.thumbNailList').slideDown();
					par.removeClass('closed').addClass('open');
				}else if(par.hasClass('open')){
					$(this).next('div.thumbNailList').slideUp();
					par.removeClass('open').addClass('closed');
				}
				
			});
			
			
		});	
	}
}

/********************************************************************************
Name:     fnHomeFeature
*********************************************************************************/

function fnHomeFeature(){
	if($('#homepage').length>0){

	    $('#homeTabs a').each(function(i) {
	        obj = $(this);
	        ref = obj.attr('href');
	        ref = ref.slice((ref.length - 4), ref.length);
	        obj.attr('href', ref);
	        obj.click(function() {
	            $('#featureArea').attr('class', '').addClass($(this).attr('href'))
	            $('.fbLatestOffersHome .offer').hide();
	            $('.fbLatestOffersHome .' + $(this).attr('href')).show();
	            $("#homepage #featureArea").stopTime();
	            $("#homepage #featureArea").everyTime(interval * 500, function(i) {
	                fnChangeTab();
	            });
	            return false;
	        })
	    });
		
	}
}



function fnChangeTab(){
	str = 'tab' + count;
	$('#featureArea').attr('class', '').addClass(str);
	$('.fbLatestOffersHome .offer').hide();
	$('.fbLatestOffersHome .' + str).show();
	
	if(count > (tabs-1)){
		count = 1;
	}else{
		count++;
	}
	
}