preLoadImage = new Image();

String.prototype.trim = function() {
	a = this.replace(/^\s+/, '');
	return a.replace(/\s+$/, '');
};
var bodytag = $("body")[0];
function setActiveStyleSheet(title) {
	bodytag.className = title;
	createCookie("style", title, 365);
//	$('#style_switch a').removeClass('style_on');
	$('#custom1').removeClass('custom1on');
	$('#custom2').removeClass('custom2on');
	$('#custom3').removeClass('custom3on');
	$('#custom4').removeClass('custom4on');
	$('#custom5').removeClass('custom5on');
	$('#custom6').removeClass('custom6on');
	switch(title) {
	case 'custom1':
	  $('#custom1').addClass('custom1on');
	  break;
	case 'custom2':
	  $('#custom2').addClass('custom2on');
	  break;
	case 'custom3':
	  $('#custom3').addClass('custom3on');
	  break;
	case 'custom4':
	  $('#custom4').addClass('custom4on');
	  break;
	case 'custom5':
	  $('#custom5').addClass('custom5on');
	  break;
	case 'custom6':
	  $('#custom6').addClass('custom6on');
	  break;
	}
}
function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}
function setBucket() {
  var cookie = readCookie("style");
  var title = cookie ? cookie : 'custom1';
  setActiveStyleSheet(title);
}
var cookie = readCookie("style");
var title = cookie ? cookie : 'custom1';
setActiveStyleSheet(title);
function selected_menu(id) {
	$('#'+id).addClass('main_on');
	$('#'+id).addClass(id+'_on');
}
function selected_submenu(id) {
	$('#'+id).addClass('submenuon');
}
function featureOver(id,pos){
	id.style.backgroundPosition = pos;
	id.style.cursor = "pointer";
}
function featureOut(id,pos){
	id.style.backgroundPosition = pos;
	id.style.cursor = "";
}
function featureClick(id){
//	link = $(id);
	link = document.getElementById(id);
	if(link != undefined) {
		location.href = link.href;
	}
}
function scrollArea(fromPage,toPage,amount){
	if(fromPage < toPage) {
		$('#page'+fromPage).animate( {left: '-'+amount+'px'}, {duration: 800, queue: false});
		$('#page'+toPage).animate( {left: '0px'}, {duration: 800, queue: false});
	}
	else {
		$('#page'+fromPage).animate( {left: amount+'px'}, {duration: 800, queue: false});
		$('#page'+toPage).animate( {left: '0px'}, {duration: 800, queue: false});
	}
}
function scrollPage(id,toPage,amount){
	$(id).animate( {left: '-'+(amount * toPage)+'px'}, {duration: 600, queue: false});
}
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		var relstring = anchor.getAttribute("rel");
		if(relstring){
			if (anchor.getAttribute("href") && relstring.search("/external/"))
 	  			anchor.target = "_blank";
 	  	}
	}
}

function loadRandom() {

	var randomnumber=Math.floor(Math.random()*2)
	switch(randomnumber) {
		case 1:
			AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','550','height','434','src','/images/shutterly-fabulous','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','/images/shutterly-fabulous' );
			break;
		default:
			AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','550','height','434','src','/carousel/shutterly-fabulous-colours2','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','/carousel/shutterly-fabulous-colours2' );
	}
}

//////////////////// FORMS ////////////////////////////////////////////////////////////////////////////
function formTestContact() {
	var error = false;
	var name = $('#name').val().trim();
	if(name == ""){
		$('#name').animate( {backgroundColor: 'red'}, {duration: 200, queue: true});
		$('#name').animate( {backgroundColor: 'white'}, {duration: 200, queue: true});
		error = true;
	}
	var email = $('#email').val().trim();
	if(!isValidEmail(email)){
		$('#email').animate( {backgroundColor: 'red'}, {duration: 200, queue: true});
		$('#email').animate( {backgroundColor: 'white'}, {duration: 200, queue: true});
		error = true;
	}
	var telephone = $('#telephone').val().trim();
	if(telephone == ""){
		$('#telephone').animate( {backgroundColor: 'red'}, {duration: 200, queue: true});
		$('#telephone').animate( {backgroundColor: 'white'}, {duration: 200, queue: true});
		error = true;
	}
	var postcode = $('#postcode').val().trim();
	if(postcode == ""){
		$('#postcode').animate( {backgroundColor: 'red'}, {duration: 200, queue: true});
		$('#postcode').animate( {backgroundColor: 'white'}, {duration: 200, queue: true});
		error = true;
	}
	var address = $('#caddress').val().trim();
	if(address == ""){
		$('#caddress').animate( {backgroundColor: 'red'}, {duration: 200, queue: true});
		$('#caddress').animate( {backgroundColor: 'white'}, {duration: 200, queue: true});
		error = true;
	}
	var hear = $('#hear').val().trim();
	if(hear == ""){
		$('#hear').animate( {backgroundColor: 'red'}, {duration: 200, queue: true});
		$('#hear').animate( {backgroundColor: 'white'}, {duration: 200, queue: true});
		error = true;
	}
	if(!error){
		if($('#brochure:checked').val() == null){
			valueBroch = "No";
		} else {
			valueBroch = "Yes";
		}
		$.get("/sendmail_contact.php", { 
			brochure: valueBroch,
			name: name,
			telephone: telephone,
			email: email,
			postcode: postcode,
			hear: hear,
			enquiry: $('#enquiry').val(),
			address: address,
			ts: $('#ts').val()
			}, emailSentContact );
	}
	else {
//		$('#divmessage').show();
	}
}
function emailSentContact(data) {
	if(data == "OK"){
		$('#frmcontact').before('<img src="images/forms-thankyou.gif" width="499" height="475" id="frmthankyou" />');
		$('#frmcontact').remove();
	}
	else {
//		$('#error').show();
	}
}
function formTestQuote() {
	var error = false;
	var name = $('#name').val().trim();
	if(name == ""){
		$('#name').animate( {backgroundColor: '#9B1928'}, {duration: 200, queue: true});
		$('#name').animate( {backgroundColor: 'white'}, {duration: 200, queue: true});
		error = true;
	}
	var email = $('#email').val().trim();
	if(!isValidEmail(email)){
		$('#email').animate( {backgroundColor: '#9B1928'}, {duration: 200, queue: true});
		$('#email').animate( {backgroundColor: 'white'}, {duration: 200, queue: true});
		error = true;
	}
	var telephone = $('#telephone').val().trim();
	if(telephone == ""){
		$('#telephone').animate( {backgroundColor: '#9B1928'}, {duration: 200, queue: true});
		$('#telephone').animate( {backgroundColor: 'white'}, {duration: 200, queue: true});
		error = true;
	}
	var county = $('#county').val().trim();
	if(county == ""){
		$('#county').animate( {backgroundColor: '#9B1928'}, {duration: 200, queue: true});
		$('#county').animate( {backgroundColor: 'white'}, {duration: 200, queue: true});
		error = true;
	}
	var postcode = $('#postcode').val().trim();
	if(postcode == ""){
		$('#postcode').animate( {backgroundColor: '#9B1928'}, {duration: 200, queue: true});
		$('#postcode').animate( {backgroundColor: 'white'}, {duration: 200, queue: true});
		error = true;
	}
	var hear = $('#hear').val().trim();
	if(hear == ""){
		$('#hear').animate( {backgroundColor: '#9B1928'}, {duration: 200, queue: true});
		$('#hear').animate( {backgroundColor: 'white'}, {duration: 200, queue: true});
		error = true;
	}
	if($('#finished_yes:checked').val() == null && $('#finished_no:checked').val() == null){
		$('#finished_required').show();
		error = true;
	}
	else {
		$('#finished_required').hide();
	}
	if(!error){
		if($('#finished_yes:checked').val() == null){
			valueFinished = "No";
		} else {
			valueFinished = "Yes";
		}
		$.get("/sendmail_quote.php", {
			name: name,
			telephone: telephone,
			email: email,
			county: county,
			postcode: postcode,
			hear: hear,
			sizes: $('#sizes').val(),
			rooms: $('#rooms').val(),
			information: $('#information').val(),
			finished: valueFinished,
			ts: $('#ts').val()
			}, emailSentQuote );
	}
	else {
//		$('#divmessage').show();
	}
}
function emailSentQuote(data) {
	if(data == "OK"){
		$('#frmpricequote').before('<img src="images/forms-thankyou.gif" width="499" height="475" id="frmthankyou" />');
		$('#frmpricequote').remove();
	}
	else {
//		$('#error').show();
	}
}

function formTestWhloesale() {
	var error = false;
	var name = $('#name').val().trim();
	if(name == ""){
		$('#name').animate( {backgroundColor: 'red'}, {duration: 200, queue: true});
		$('#name').animate( {backgroundColor: 'white'}, {duration: 200, queue: true});
		error = true;
	}
	var companyname = $('#companyname').val().trim();
	if(companyname == ""){
		$('#companyname').animate( {backgroundColor: 'red'}, {duration: 200, queue: true});
		$('#companyname').animate( {backgroundColor: 'white'}, {duration: 200, queue: true});
		error = true;
	}
	var companyregnumber = $('#companyregnumber').val().trim();
	if(companyregnumber == ""){
		$('#companyregnumber').animate( {backgroundColor: 'red'}, {duration: 200, queue: true});
		$('#companyregnumber').animate( {backgroundColor: 'white'}, {duration: 200, queue: true});
		error = true;
	}
	var caddress = $('#caddress').val().trim();
	if(caddress == ""){
		$('#caddress').animate( {backgroundColor: 'red'}, {duration: 200, queue: true});
		$('#caddress').animate( {backgroundColor: 'white'}, {duration: 200, queue: true});
		error = true;
	}
	var postcode = $('#postcode').val().trim();
	if(postcode == ""){
		$('#postcode').animate( {backgroundColor: 'red'}, {duration: 200, queue: true});
		$('#postcode').animate( {backgroundColor: 'white'}, {duration: 200, queue: true});
		error = true;
	}
	var telephone = $('#telephone').val().trim();
	if(telephone == ""){
		$('#telephone').animate( {backgroundColor: 'red'}, {duration: 200, queue: true});
		$('#telephone').animate( {backgroundColor: 'white'}, {duration: 200, queue: true});
		error = true;
	}
	var email = $('#email').val().trim();
	if(!isValidEmail(email)){
		$('#email').animate( {backgroundColor: 'red'}, {duration: 200, queue: true});
		$('#email').animate( {backgroundColor: 'white'}, {duration: 200, queue: true});
		error = true;
	}
	if(!error){
		$.get("/sendmail_wholesale.php", {
			name: name,
			companyname: companyname,
			companyregnumber: companyregnumber,
			caddress: caddress,
			postcode: postcode,
			telephone: telephone,
			email: email,
			webaddress: $('#webaddress').val(),
			nature: $('#nature').val(),
			information: $('#information').val(),
			ts: $('#ts').val()
			}, emailSentWhloesale );
	}
}
function emailSentWhloesale(data) {
	if(data == "OK"){
		$('#frmwholesale').before('<img src="images/forms-thankyou.gif" width="499" height="475" id="frmthankyou" />');
		$('#frmwholesale').remove();
	}
}
function isValidEmail(email){
    var RegExp = /^((([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+(\.([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+)*)@((((([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.))*([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/
    if(RegExp.test(email)){
        return true;
    }else{
        return false;
    }
}
//////////////////// scroll by jquery ////////////////////////////////////////////////////////////////////////////
jQuery.getPos = function (e)
{
	var l = 0;
	var t  = 0;
	var w = jQuery.intval(jQuery.css(e,'width'));
	var h = jQuery.intval(jQuery.css(e,'height'));
	var wb = e.offsetWidth;
	var hb = e.offsetHeight;
	while (e.offsetParent){
		l += e.offsetLeft + (e.currentStyle?jQuery.intval(e.currentStyle.borderLeftWidth):0);
		t += e.offsetTop  + (e.currentStyle?jQuery.intval(e.currentStyle.borderTopWidth):0);
		e = e.offsetParent;
	}
	l += e.offsetLeft + (e.currentStyle?jQuery.intval(e.currentStyle.borderLeftWidth):0);
	t  += e.offsetTop  + (e.currentStyle?jQuery.intval(e.currentStyle.borderTopWidth):0);
	return {x:l, y:t, w:w, h:h, wb:wb, hb:hb};
};
jQuery.getClient = function(e)
{
	if (e) {
		w = e.clientWidth;
		h = e.clientHeight;
	} else {
		w = (window.innerWidth) ? window.innerWidth : (document.documentElement && document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body.offsetWidth;
		h = (window.innerHeight) ? window.innerHeight : (document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.offsetHeight;
	}
	return {w:w,h:h};
};
jQuery.getScroll = function (e)
{
	if (e) {
		t = e.scrollTop;
		l = e.scrollLeft;
		w = e.scrollWidth;
		h = e.scrollHeight;
	} else  {
		if (document.documentElement && document.documentElement.scrollTop) {
			t = document.documentElement.scrollTop;
			l = document.documentElement.scrollLeft;
			w = document.documentElement.scrollWidth;
			h = document.documentElement.scrollHeight;
		} else if (document.body) {
			t = document.body.scrollTop;
			l = document.body.scrollLeft;
			w = document.body.scrollWidth;
			h = document.body.scrollHeight;
		}
	}
	return { t: t, l: l, w: w, h: h };
};
jQuery.intval = function (v)
{
	v = parseInt(v);
	return isNaN(v) ? 0 : v;
};
jQuery.fn.ScrollTo = function(s) {
	o = jQuery.speed(s);
	return this.each(function(){
		new jQuery.fx.ScrollTo(this, o);
	});
};
jQuery.fx.ScrollTo = function (e, o)
{
	var z = this;
	z.o = o;
	z.e = e;
	z.p = jQuery.getPos(e);
	z.s = jQuery.getScroll();
	z.clear = function(){clearInterval(z.timer);z.timer=null};
	z.t=(new Date).getTime();
	z.step = function(){
		var t = (new Date).getTime();
		var p = (t - z.t) / z.o.duration;
		if (t >= z.o.duration+z.t) {
			z.clear();
			setTimeout(function(){z.scroll(z.p.y, z.p.x)},13);
		} else {
			st = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.y-z.s.t) + z.s.t;
			sl = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.x-z.s.l) + z.s.l;
			z.scroll(st, sl);
		}
	};
	z.scroll = function (t, l){window.scrollTo(l, t)};
	z.timer=setInterval(function(){z.step();},13);
};
//$(document).ready(maininit);
//function maininit() {
//    $('a[href^="#"]').click(function() {
//        var parts        = this.href.split('#');
//        var scrolltarget = '#' + parts[1];
//        $(scrolltarget).ScrollTo(1200);
//        return false;
//    });
//};
/*
 * jQuery Color Animations
 * Copyright 2007 John Resig
 * Released under the MIT and GPL licenses.
 */
(function(jQuery){
	// We override the animation for all of these color styles
	jQuery.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'], function(i,attr){
		jQuery.fx.step[attr] = function(fx){
			if ( fx.state == 0 ) {
				fx.start = getColor( fx.elem, attr );
				fx.end = getRGB( fx.end );
			}
			fx.elem.style[attr] = "rgb(" + [
				Math.max(Math.min( parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0)
			].join(",") + ")";
		}
	});
	// Color Conversion functions from highlightFade
	// By Blair Mitchelmore
	// http://jquery.offput.ca/highlightFade/
	// Parse strings looking for color tuples [255,255,255]
	function getRGB(color) {
		var result;
		// Check if we're already dealing with an array of colors
		if ( color && color.constructor == Array && color.length == 3 )
			return color;
		// Look for rgb(num,num,num)
		if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
			return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];
		// Look for rgb(num%,num%,num%)
		if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))
			return [parseFloat(result[1])*2.55, parseFloat(result[2])*2.55, parseFloat(result[3])*2.55];
		// Look for #a0b1c2
		if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))
			return [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];
		// Look for #fff
		if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))
			return [parseInt(result[1]+result[1],16), parseInt(result[2]+result[2],16), parseInt(result[3]+result[3],16)];
		// Otherwise, we're most likely dealing with a named color
		return colors[jQuery.trim(color).toLowerCase()];
	}
	function getColor(elem, attr) {
		var color;
		do {
			color = jQuery.curCSS(elem, attr);
			// Keep going until we find an element that has color, or we hit the body
			if ( color != '' && color != 'transparent' || jQuery.nodeName(elem, "body") )
				break;
			attr = "backgroundColor";
		} while ( elem = elem.parentNode );
		return getRGB(color);
	};
	// Some named colors to work with
	// From Interface by Stefan Petre
	// http://interface.eyecon.ro/
	var colors = {
		aqua:[0,255,255],
		azure:[240,255,255],
		beige:[245,245,220],
		black:[0,0,0],
		blue:[0,0,255],
		brown:[165,42,42],
		cyan:[0,255,255],
		darkblue:[0,0,139],
		darkcyan:[0,139,139],
		darkgrey:[169,169,169],
		darkgreen:[0,100,0],
		darkkhaki:[189,183,107],
		darkmagenta:[139,0,139],
		darkolivegreen:[85,107,47],
		darkorange:[255,140,0],
		darkorchid:[153,50,204],
		darkred:[139,0,0],
		darksalmon:[233,150,122],
		darkviolet:[148,0,211],
		fuchsia:[255,0,255],
		gold:[255,215,0],
		green:[0,128,0],
		indigo:[75,0,130],
		khaki:[240,230,140],
		lightblue:[173,216,230],
		lightcyan:[224,255,255],
		lightgreen:[144,238,144],
		lightgrey:[211,211,211],
		lightpink:[255,182,193],
		lightyellow:[255,255,224],
		lime:[0,255,0],
		magenta:[255,0,255],
		maroon:[128,0,0],
		navy:[0,0,128],
		olive:[128,128,0],
		orange:[255,165,0],
		pink:[255,192,203],
		purple:[128,0,128],
		violet:[128,0,128],
		red:[255,0,0],
		silver:[192,192,192],
		white:[255,255,255],
		yellow:[255,255,0]
	};
})(jQuery);
/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */
/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
// maxmind expander and collapser
(function($) {
	$.ajaxSetup({
		type: 'POST',
		timeout: 5000,
		dataType: 'text'
	});
	function maxmindExpand(){
		$('#maxmindWrapper').slideDown('fast');
	}
	function maxmindCollapse(){
		$('#maxmindWrapper').slideUp('fast');
	}
	$.maxmind_showDiv = function(data) {
		if (data == 'US' && ($.cookie('shutt_maxmind') == null)) {
			$('#maxmind').html('<div id="maxmindWrapper"><div><a href="http://www.theshutterstore.com/" title="Window shutters USA"><img src="/images/USA-flag.jpg" width="43" height="43" alt="USA flag" /></a><p class="maxmindText"><span class="maxmindTitle">Looking for window shutters in the USA?</span><br />Click here to visit <a href="http://www.theshutterstore.com/" title="Window shutters USA">The Shutter Store - our USA partners</a> or <span id="maxmindButtonClose" class="like-a-link">click here to close this notice</span></p></div></div>');
			$('#maxmindWrapper').hide();
			$('#maxmindWrapper').fadeIn('slow');
			$('#maxmindButtonClose').click(function(event){if(this == event.target){maxmindCollapse();$.cookie('shutt_maxmind', 'US', { expires: 30, path: '/' });}});
		}
	}
	$.maxmind_displayError = function(data, msg) {
		if (data.status) { msg = data.status + ', ' + data.statusText; }
		else { msg = msg + ': ' + data; }
		$('#maxmind').html(msg);
	}
	$.maxmind_getMaxmindGeoCountry = function() {
		$.ajax({
			url: '/lib/class.maxmind.php',
			data: { x: 1 },
			success: function(data) { $.maxmind_showDiv(data); },
			error: function(data) { $.maxmind_displayError(data, 'error'); }
		});
	}
	$(function() {
		$.maxmind_getMaxmindGeoCountry();
	});
})(jQuery);

// Spash Image Scroll
var spashImagePosition = 0;
var spashImages;

var firstScroll = 6500;
var nextScroll = 5000;
var scrollForward = true;
var scrollTimer;
var leftMouseOver = false;
var rightMouseOver = false;
var displayButton = 1500;

function spashImageView() {
	spashImages = $('#image_splash img');
		
	$('#image_splash_left').mouseenter(function(event){ leftMouseOver = true;clearTimeout(scrollTimer);});
	$('#image_splash_left').mouseleave(function(event){ leftMouseOver = false;scrollTimer = setTimeout(autoScroll,firstScroll);});

	$('#image_splash_right').mouseenter(function(event){ $('#image_splash_right span').fadeIn('fast');rightMouseOver = true;clearTimeout(scrollTimer);});
	$('#image_splash_right').mouseleave(function(event){ $('#image_splash_right span').fadeOut('fast');rightMouseOver = false;scrollTimer = setTimeout(autoScroll,firstScroll);});
	$('#image_splash_right').click(spashImageRightClick);
	
	scrollTimer = setTimeout(autoScroll,firstScroll);
}
function autoScroll() {
	if(scrollForward){
		spashImageRight();
	}
	else {
		spashImageLeft();
	}
	scrollTimer = setTimeout(autoScroll,nextScroll);
}
function spashImageLeftClick() {
	clearTimeout(scrollTimer);
	scrollTimer = false;
	spashImageLeft();
}
function spashImageLeft() {
	spashImagePosition--;
	$('#image_splash_left span').fadeOut('fast');
	if(spashImagePosition == 0){
		$('#image_splash_left').unbind('mouseenter')
		$('#image_splash_left').unbind('mouseleave')
		$('#image_splash_left').unbind('click')
		$('#image_splash_left').mouseenter(function(event){ leftMouseOver = true;clearTimeout(scrollTimer);});
		$('#image_splash_left').mouseleave(function(event){ leftMouseOver = false;scrollTimer = setTimeout(autoScroll,firstScroll);});
		scrollForward = true;
	}
	else {
		$('#image_splash_left').unbind('mouseenter')
		$('#image_splash_left').unbind('mouseleave')
		$('#image_splash_left').unbind('click')
		$('#image_splash_left').mouseenter(function(event){ $('#image_splash_left span').fadeIn('fast');leftMouseOver = true;clearTimeout(scrollTimer);});
		$('#image_splash_left').mouseleave(function(event){ $('#image_splash_left span').fadeOut('fast');leftMouseOver = false;scrollTimer = setTimeout(autoScroll,firstScroll);});
		$('#image_splash_left').click(spashImageLeftClick);
	}
	
	if(spashImagePosition != (spashImages.length - 3)){
		$('#image_splash_right').unbind('mouseenter')
		$('#image_splash_right').unbind('mouseleave')
		$('#image_splash_right').unbind('click')
		$('#image_splash_right').mouseenter(function(event){ $('#image_splash_right span').fadeIn('fast');rightMouseOver = true;clearTimeout(scrollTimer);});
		$('#image_splash_right').mouseleave(function(event){ $('#image_splash_right span').fadeOut('fast');rightMouseOver = false;scrollTimer = setTimeout(autoScroll,firstScroll);});
		$('#image_splash_right').click(spashImageRightClick);
	}

	spashImages.slice(spashImagePosition,spashImagePosition+1).animate( {left: '0px'}, {duration: 800, queue: false});
	spashImages.slice(spashImagePosition+1,spashImagePosition+2).animate( {left: '550px'}, {duration: 800, queue: false});
	
	setTimeout(leftButtonBack,displayButton);
	
}
function leftButtonBack(){
	if(leftMouseOver && spashImagePosition != 0){$('#image_splash_left span').fadeIn('fast');}
}
function spashImageRightClick() {
	clearTimeout(scrollTimer);
	scrollTimer = false;
	spashImageRight();
}
function spashImageRight() {
	spashImagePosition++;
	$('#image_splash_right span').fadeOut('fast');
	if(spashImagePosition == (spashImages.length - 3)){
		$('#image_splash_right').unbind('mouseenter')
		$('#image_splash_right').unbind('mouseleave')
		$('#image_splash_right').unbind('click')
		$('#image_splash_right').mouseenter(function(event){ rightMouseOver = true;clearTimeout(scrollTimer);});
		$('#image_splash_right').mouseleave(function(event){ rightMouseOver = false;scrollTimer = setTimeout(autoScroll,firstScroll);});
		scrollForward = false;
	}
	else {
		$('#image_splash_right').unbind('mouseenter')
		$('#image_splash_right').unbind('mouseleave')
		$('#image_splash_right').unbind('click')
		$('#image_splash_right').mouseenter(function(event){ $('#image_splash_right span').fadeIn('fast');rightMouseOver = true;clearTimeout(scrollTimer);});
		$('#image_splash_right').mouseleave(function(event){ $('#image_splash_right span').fadeOut('fast');rightMouseOver = false;scrollTimer = setTimeout(autoScroll,firstScroll);});
		$('#image_splash_right').click(spashImageRightClick);
	}
	
	if(spashImagePosition != 0){
		$('#image_splash_left').unbind('mouseenter')
		$('#image_splash_left').unbind('mouseleave')
		$('#image_splash_left').unbind('click')
		$('#image_splash_left').mouseenter(function(event){ $('#image_splash_left span').fadeIn('fast');leftMouseOver = true;clearTimeout(scrollTimer);});
		$('#image_splash_left').mouseleave(function(event){ $('#image_splash_left span').fadeOut('fast');leftMouseOver = false;scrollTimer = setTimeout(autoScroll,firstScroll);});
		$('#image_splash_left').click(spashImageLeftClick);
	}
	
	spashImages.slice(spashImagePosition-1,spashImagePosition).animate( {left: '-550px'}, {duration: 800, queue: false});
	spashImages.slice(spashImagePosition,spashImagePosition+1).animate( {left: '0px'}, {duration: 800, queue: false});

	setTimeout(rightButtonBack,displayButton);

}
function rightButtonBack(){
	if(rightMouseOver && spashImagePosition != (spashImages.length - 3)){$('#image_splash_right span').fadeIn('fast');}
}

// Image popup
function imagePopupCapture(){
	$('.pop_image').click(imagePopup);
}
function imagePopup(){
	
	$('body').append('<div id="image_black_out"></div>');
	$('#image_black_out').height($('body').height());
	$('body').append('<div id="image_display"><div><img id="image_diplay_image" src="'+$(this).attr('href')+'"/><a>Close</a></div></div>');
	$('#image_display div').width($('#image_diplay_image').width() + 20);
	$('#image_display').click(imagePopupClose);
	$('#image_display a').click(imagePopupClose);
	return false;
}
function imagePopupClose(){
	$('#image_display').remove();
	$('#image_black_out').remove();
}
function loadCode(){
	$.get("token.php",function(txt){$("form").append('<input type="hidden" name="ts" id="ts" value="'+txt+'" />');});
}

window.onload = function(e) {
	setBucket();
	externalLinks();
	$('a[href="#"]').attr('href','javascript:void(0);')
}

function showFlash(){
	var so = new SWFObject("/virtual-tour/files/pano.swf", "pano", "550", "380", "9", "#282828"); 
	so.addVariable("xml_file","/virtual-tour/shutter-showroom-small.xml");
	so.addParam("allowFullScreen","true");
	so.addParam("allowScriptAccess","sameDomain");
	so.write("flashcontent");
	window.document["pano"].focus();
}