document.write('<link href="'+rootURL+'highlandheritage/media/css/javascript.css" rel="stylesheet" type="text/css" media="all" />');
document.write('<link href="'+rootURL+'highlandheritage/media/css/colorbox.css" rel="stylesheet" type="text/css" media="all" />');

var $j = jQuery.noConflict();

$j(document).ready( function() {
	$j('.menu div.container').prepend('<div class="fontchanger"><a href="javascript:changetoLarge()" class="a_l" title="Change the text to the largest size.">Aa</a><a href="javascript:changetoMedium()" class="a_m" title="Change the text to a larger size.">Aa</a><a href="javascript:changetoDefault()" class="a_s" title="Change the text to the default size.">Aa</a><span>Increase text size: &nbsp; <img src="'+rootURL+'highlandheritage/media/interface/arrow_right.gif" alt="" /></span><div class="clear"></div></div>');
	
	$j('.menu li').hover( function() {
		$j(this).addClass('over');
	},function() {
		$j(this).removeClass('over');
	});
	$j('.gallery').imageGallery( { 'itemButtons':true, transspeed: '2000' });
	$j('.qtrs').each( function (){
		var qtrs = $j(this)
		qtrs.find('.tour_summary').equalHeight();
		if($j('.mm_listitem').length > 0) {
			qtrs.find('.mm_listitem').equalHeight( { equalitem:".media_container" }).find('h5 a').attr('rel','textlinkImage').filter(':not(.video)').colorbox().end().filter('.video').colorbox({iframe:true, width:682, height:430 }).end().each(function() {
				a = $j(this);
				a.parents('.mm_listitem').children('.media_container').children('img').wrap('<a href="'+a.attr('href')+'" title="'+a.attr('title')+'" class="'+a.attr('class')+'" target="_blank" rel="imagelinkImage" />');
			}).parents('.mm_listitem').find('.media_container a').filter(':not(.video)').colorbox().end().filter('.video').colorbox({iframe:true, width:682, height:430 }).end();
		}
	});
	$j('.sologalleryLink').colorbox({iframe:true, width:682, height:430 });
	
	$j('.selecttrans select').change(function() {
		var selpoint = $j(this).parents('.selecttrans').siblings('.selectpoint');
		if(this.selectedIndex == 0) {
			selpoint.css('visibility','visible');
		} else {
			selpoint.css('visibility','hidden');
		}
	});
});

(function($j) {

$j.fn.equalHeight = function(options) {
	defaults = {
		rowlength:4,
		equalitem:".padding:last p:first"
	}
	var o = $j.extend(defaults,options);
	var tallest = new Array();
	var row = 0;
	this.each(function(i) {
		if(i % o.rowlength == 0) {
			row++;
		}
		var e = $j(this);
		e.find(o.equalitem).each(function() {
			tallest[row] = Math.max ($j(this).height(), tallest[row] || 0);
		})
	});
	row = 0;
	return this.each(function(i) {
		if(i % o.rowlength == 0) {
			row++;
		}
		var e = $j(this);
		e.each(function() {
			$j(this).find(o.equalitem).css({"height": tallest[row] || 0});
		});
	});
};
}) ($j)

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);
}
