document.write('<style type="text/css">.revealedDiv, .ui-tabs-hide { display:none; } .slided { overflow:hidden; }</style>');

var $j = jQuery.noConflict();

var slideTimer;
var mixArray;
var lastDisplayedArray;
var lastChanged;

$j(document).ready( function()
	{
		var locat = location.href;
		
		$j(".mainmenu ul li a").each(function(){
			if(locat.indexOf(this.href) >= 0 || (locat == this.href.replace('Home.aspx',"")))
			{
				this.parentNode.className += " active"
			}
		});		
		$j(".subnav ul li a").each(function(){
			if(locat.indexOf(this.href) >= 0 || (locat == this.href.replace('Home.aspx',"")))
			{
				this.parentNode.className += " active"
			}
		});		
		
    	$j('.header div.links').prepend('<span>Font size: <a href="javascript:changetoDefault()" class="a_s" title="Change the text to the default size.">A</a> | <a href="javascript:changetoMedium()" class="a_m" title="Change the text to a larger size.">A</a> | <a href="javascript:changetoLarge()" class="a_l" title="Change the text to the largest size.">A</a></span> &nbsp; ');
    		
    	$j(".revealDiv").click( function () {
			var mySection = $j(this).siblings('.revealedDiv');
			if($j(this).hasClass('activeReveal')) {
			    $j(this).removeClass('activeReveal');
			    mySection.stop(true,true).show().animate({ height: 'hide' }, 'slow');
			}
			else {
			    $j(this).addClass('activeReveal');
			    mySection.stop(true,true).hide().animate({ height: 'show' }, 'slow');
			}
		});
		
		$j('.drop_head').click(function() {
			var sibling = $j(this).siblings('.drop_body');
			if(sibling.css('display') == 'block') {
				sibling.stop(true,true).animate({height:'hide'},'slow');
				$j(this).find('input').attr('checked',false);
				$j(this).parent().removeClass("active");
			} else {
				sibling.stop(true,true).animate({height:'show'},'slow');
				$j(this).find('input').attr('checked',true);
				$j(this).parent().addClass("active");
			}
			if($j(this).attr('nodeName') == "A") {
				return false;
			}
		});
		
		$j('.drop_body').each( function() {
			if(!$j(this).parent().hasClass('active')) {
				$j(this).hide();
			}
		});
		
		$j('.inputBorder').focus( function() {
			var myPopup = $j(this).siblings('.popup');
			
			myPopup.stop(true,true).hide().animate({ height: 'show' }, 'slow');
		});
		
		$j('.inputBorder').blur( function() {
			var myPopup = $j(this).siblings('.popup');

			myPopup.stop(true,true).show().animate({ height: 'hide' }, 'slow');
		});
		
		$j(".tabs").tabs( {fx: { opacity: 'toggle' } });
		$j(".packtabs").tabs( {fx: { opacity: 'toggle' }, tabTemplate: '<li><a href="#{href}"><span>#{label}</span></a></li>' });
		$j(".package").each(function() {
			myContained = $j(this).find('.packageListContainer');
			myContained.attr('rel', 0);
			$j(this).find('.packagedetail').addClass('hiddenChan').hide();
			$j(this).find('.packagedetail:eq(0)').removeClass('hiddenChan').addClass('activeChan').show();
			if(myContained.find('div[class!=clear]').length > 12) {
				myContained.css('width','1000%'); 
				myContained.css('height','320px');
				var newContents = "";
				myContained.find('div[class!=clear]').wrap('<div class="packholder"></div>');
				for(var i=0; i < myContained.find('div.packholder').length; i++) {
					if(i % 12 == 0) {
						newContents += '<div class="packagepage">';
					}
					newContents += myContained.find('div.packholder:eq('+i+')').html();
					if((i+1) % 12 == 0) {
						newContents += "</div>";
					}
				}
				myContained.html(newContents);
				$j(this).find('.packageList').append('<div class="slidebuttons"><div class="leftButton"><div class="inactive"></div></div><div class="rightButton"><div></div></div>&nbsp;More&nbsp;');
			}
			$j(this).find('.packageListContainer a').click(function() {
				var targetHref = $j(this).attr('href');
				if(targetHref.indexOf('#') == 0) {
					if(!$j(targetHref).hasClass('activeChan')) {
						$j(targetHref).parents('.package').find('.nextChan').removeClass('nextChan');
						$j(targetHref).addClass('nextChan');
						$j(targetHref).parents('.package').find('.activeChan').stop(true,true).animate( { opacity:'hide' }, 500, function() {
							$j(this).removeClass('activeChan').addClass('hiddenChan');
							$j(this).parents('.package').find('.nextChan').removeClass('hiddenChan').addClass('activeChan').removeClass('nextChan').animate( { opacity:'show' }, 500);
						});
					}
					return false;
				}
			})
		});
		$j('.leftButton').click(moveLeft);
		$j('.rightButton').click(moveRight);
		
		if($j('.comparisontable').length > 0) {
			$j('.selectPacks').html('<span class="popupSpanHolder photoMargins left_content_space"><a href="javascript:;"><span class="popupTitle">Select Packs</span><span class="popupSpan"><input type="checkbox" checked="checked" /> Variety Pack<br /><input type="checkbox" checked="checked" /> Family Pack<br /><input type="checkbox" checked="checked" /> Ultimate Pack<br /><input type="checkbox" checked="checked" /> Kids Pack</span></a></span><span class="labelText">Show: </span>');
			$j('.selectPacks').find('input').click( function() {
				$j('.comparisontable').find('tbody tr').hide().removeClass('odd');
				$j('.selectPacks').find('input').each(function(index) {
					var i = index +1;
					if($j(this).attr('checked')) {
						$j('.comparisontable').find('tr').find('td:eq('+i+')').show();
						$j('.comparisontable').find('tr').find('th:eq('+i+')').show();
						$j('.comparisontable').find('tr[class~=pk'+i+']').show();
					} else {
						$j('.comparisontable').find('tr').find('td:eq('+i+')').hide();
						$j('.comparisontable').find('tr').find('th:eq('+i+')').hide();
					}
				});
				$j('.comparisontable').find('tr:visible').each( function(index) {
					if(index % 2 != 0) {
						$j(this).addClass('odd');
					}
				});
			})
		}
		
		
		$j(".slider").slider({
			orientation: "vertical",
			range: "max",
			min: 0,
			max: 100,
			value: 100,
			slide: function(event, ui) {
				var contents = $j(this).siblings('.slided').find('.contents');
				contents.css('margin-top',(-(contents.attr('offsetHeight')*((100-ui.value)/100))+(($j(this).siblings('.slided').attr('offsetHeight')*((100-ui.value)/100)))) + "px");
			}
		});
		
		var pageHash = location.hash;
		pageHash = pageHash.substring(1,pageHash.length);
		pageHash = pageHash.replace(/%20/g,' ');
		var split = pageHash.split('_');
		if(split.length > 1) {
			$j(".tabs").tabs( 'select' , split[0] );
		}
		var targetNode = document.getElementById(pageHash);
		if(targetNode) {
			var mySection = $j(targetNode).siblings('.revealedDiv');
			if(!$j(targetNode).hasClass('activeReveal')) {
				$j(this).addClass('activeReveal');
				mySection.stop(true,true).hide().animate({ height: 'show' }, 'slow');
			}
		}
		levelPanels('.thirdsDiv');
		levelPanels('.left_content');
	}
);

function moveLeft() {
	var parentList = $j(this).parents('.packageList');
	var currentLeft = parseInt(parentList.find('.packageListContainer').attr('rel'));
	if(currentLeft < 0) {
		currentLeft += parentList.find('.packageListContainer').parent().attr('offsetWidth');
		parentList.find('.packageListContainer').stop(true,true).animate( { marginLeft: currentLeft +"px" }, 1000);
		$j(this).parent().find('.rightButton div.inactive').removeClass('inactive');
		if(currentLeft >= 0) {
			$j(this).find('div').addClass('inactive');
		} else {
			$j(this).find('div').removeClass('inactive');
		}
		parentList.find('.packageListContainer').attr('rel', currentLeft);
	}
}

function moveRight() {
	var parentList = $j(this).parents('.packageList');
	var currentLeft = parseInt(parentList.find('.packageListContainer').attr('rel'));
	var pageWidth = parentList.find('.packageListContainer').parent().attr('offsetWidth');
	if(currentLeft - pageWidth > -(parentList.find('.packageListContainer').find('.packagepage').length) * pageWidth) {
		currentLeft -= parentList.find('.packageListContainer').parent().attr('offsetWidth');
		parentList.find('.packageListContainer').stop(true,true).animate( { marginLeft: currentLeft +"px" }, 1000);
		$j(this).parent().find('.leftButton div.inactive').removeClass('inactive');
		if(currentLeft - pageWidth >= -(parentList.find('.packageListContainer').children().length) * pageWidth) {
			$j(this).find('div').addClass('inactive');
		} else {
			$j(this).find('div').removeClass('inactive');
		}
		parentList.find('.packageListContainer').attr('rel', currentLeft);
	}
}

function levelPanels(className) {
	var panels = $j(className);
	var currentItems = new Array();
	for(var i =0; i < panels.children().length; i++) {
		var thisPanel = panels.children(':eq('+i+')')
		if(thisPanel.hasClass('trd_box') || thisPanel.hasClass('grey_grad') || thisPanel.hasClass('half_box') || thisPanel.hasClass('twotrd_box')) {
			currentItems.push(thisPanel);
			if(!(thisPanel.next(':first').hasClass('trd_box') || thisPanel.next(':first').hasClass('grey_grad') || thisPanel.next(':first').hasClass('half_box') || thisPanel.next(':first').hasClass('twotrd_box'))) {
				var targetHeight = 0;
				for(var j=0; j < currentItems.length; j++) {
					if(currentItems[j].attr('offsetHeight') > targetHeight) {
						targetHeight = currentItems[j].attr('offsetHeight');
					}
				}
				for(var j=0; j < currentItems.length; j++) {
					if(currentItems[j].attr('offsetHeight') < targetHeight) {
						var lastItem = currentItems[j].find('.padding:eq(0)').children(':last');
						if(lastItem.hasClass('borderbox')) {
							lastItem = lastItem.find('ul:last');
						}
						if(lastItem.hasClass('bluebox')) {
							var marTop = lastItem.css('margin-top');
							if(marTop) {
								marTop = marTop.replace('px','');
							}
							lastItem.css('margin-top',(targetHeight - currentItems[j].attr('offsetHeight') + parseInt(marTop)) + "px");
						} else {
							var paddBott = lastItem.css('padding-bottom');
							if(paddBott) {
								paddBott = paddBott.replace('px','');
							}
							lastItem.css('padding-bottom',(targetHeight - currentItems[j].attr('offsetHeight') + parseInt(paddBott)) + "px");
						}
					}
				}
				currentItems = new Array();
			}
		}
	}
}

function slidersMove() {
	if(lastChanged == 0) {
		clearInterval(slideTimer);
		slideTimer = setInterval(slidersMove, 500);
	}
	var lastDisplayed = lastDisplayedArray[lastChanged];
	if($j(".floatChannels:eq(" + lastChanged + ")").find('.fc2').length > 0) {
		var newfcs = $j(".floatChannels:eq(" + lastChanged + ")").find('.fc2');
		var oldfcs = $j(".floatChannels:eq(" + lastChanged + ")").find('.fc1');
		var oldhtml = newfcs.html();
		oldfcs.html(oldhtml).show();
		newfcs.hide();
		var myhtml = "";
		for(var j=0;j< 6;j++) {
			lastDisplayed++;
			if(lastDisplayed >= mixArray[lastChanged].length) {
				lastDisplayed = 0;
			}
			myhtml += '<div class="floatChannel">' + mixArray[lastChanged][lastDisplayed] + '</div><div class="floatSpace"></div>';
		}
		lastDisplayedArray[lastChanged] = lastDisplayed;
		newfcs.html(myhtml).animate({ opacity: 'show' }, 1000);
		oldfcs.animate({ opacity: 'hide' }, 1000);
	}
	lastChanged++;
	if(lastChanged >= mixArray.length) {
		lastChanged=0;
		clearInterval(slideTimer);
		slideTimer = setInterval(slidersMove, 5000);
	}
}


var clearText = new Array('Enter post code here', 'password', 'Search Site');

function clearCheck(myInput, defaultText)
{
    /*
    for(i=0;i<clearText.length;i++)
    {
        if(myInput.value == clearText[i])
        {
            myInput.value = "";
        }
    }
    */
    if (myInput.value == defaultText) {
        myInput.value = "";
    }
}


function iotbs() {
	switcher = new switchManager();
};

var switcher;

//setup initialisation function
//.. gecko, safari, konqueror and generic
if(typeof window.addEventListener != 'undefined') {
	window.addEventListener('load', iotbs, false);
}
//.. opera 7
else if(typeof document.addEventListener != 'undefined') {
	document.addEventListener('load', iotbs, false);
}
//.. win/ie
else if(typeof window.attachEvent != 'undefined') {
	window.attachEvent('onload', iotbs);
}


//preferences manager
function switchManager() {
	//string for storing the overall custom classname
	//I was originally storing it in the body class name directly
	//but 1.7+ mozilla builds were not honouring the trailing whitespace we need
	this.string  = '';

	//store reference to body element
	this.body = document.getElementsByTagName('body')[0];

	//store the initial classname
	this.initial = this.body.className;

	//if the default classname is empty, add "iotbs"
	//because we need there to be at least one classname already -
	//the leading and trailing space in each custom classname is required,
	//but you can't set the body classname as " something" (beginning with a leading space)
	//because that may not work in Opera 7
	if(this.initial == '') {
		this.initial = 'itobs';
	}

	//look for a stored cookie
	this.cookie = this.read();

	//if it exists
	if(this.cookie != null) {
		//store cookie value to string
		this.string = this.cookie;

		//set new body class name
		this.body.className = this.initial + ' ' + this.string;
	}

	//*** dev
	//document.title = '<' + this.body.className.replace(/ /g,'+') + '>   [' + this.string.replace(/ /g,'+') + ']';
};

//set a cookie method
switchManager.prototype.set = function(days) {
	//format expiry date
	this.date = new Date();
	this.date.setTime(this.date.getTime() + ( days *24*60*60*1000));

	//store the string, replacing spaces with '#' so that leading spaces are preserved
	this.info = this.string.replace(/ /g,'#');

	//if the value is empty, set its expiry in the past to delete the cookie
	if(this.info == '') { this.date.setTime(0); }

	//create the cookie
	document.cookie = 'bodySwitcher=' + this.info
		+ '; expires=' + this.date.toGMTString()
		+ '; path=/';
};


//read a cookie method
switchManager.prototype.read = function() {
	//set null reference so we always have something to return
	this.cookie = null;

	//if a cookie exists
	if(document.cookie) {
		//if it's our cookie
		if(document.cookie.indexOf('bodySwitcher')!=-1) {
			//extract and store relevant information (turning '#' back into spaces)
			this.cookie = document.cookie.split('bodySwitcher=');
			this.cookie = this.cookie[1].split(';');
			this.cookie = this.cookie[0].replace(/#/g,' ');
		}
	}
	return this.cookie;
};


function changetoDefault() {
	switcher.string = 'default'
	switcher.body.className = " iotbs  ";
	switcher.set(365);
}

function changetoMedium() {
	switcher.string = 'medium';
	switcher.body.className = " iotbs  " + switcher.string +' ';
	switcher.set(365);
}

function changetoLarge() {
	switcher.string = 'large';
	switcher.body.className = " iotbs  " + switcher.string +' ';
	switcher.set(365);
}


function countdown(day)
{
	today = (new Date()).getTime();
	the_day = (new Date(day)).getTime();
	time = (the_day - today);
	days = (time - (time % 86400000)) / 86400000;
	time = time - (days * 86400000);
	hours = (time - (time % 3600000)) / 3600000;
	time = time - (hours * 3600000);
	mins = (time - (time % 60000)) / 60000;
	time = time - (mins * 60000);
	secs = (time - (time % 1000)) / 1000;
	if(document.getElementById('switch_time'))
	{
		document.getElementById('switch_time').innerHTML = "<strong>" +days + "</strong> days, <strong>" + hours + "</strong> hours, <strong>" + mins + "</strong> mins";
	}
}