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';
	if(!$('body').hasClass('customxmas')){
  		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-colours3','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','/carousel/shutterly-fabulous-colours3' );
	}
}

//////////////////// 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"){
		window.location = "/contact_us_thank_you.html";
//		$('#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"){
		window.location = "/price_quote_thank_you.html";
//		$('#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"){
		window.location = "/wholesale_shutters_thank_you.html";
//		$('#frmwholesale').before('<img src="images/forms-thankyou.gif" width="499" height="475" id="frmthankyou" />');
//		$('#frmwholesale').remove();
	}
}
function isValidEmail(email){
	var RegExp = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
    //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;
    }
};

// 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();
}
function hideImages(){
	$('.hide_image').hide();
}
function showimage(width,height,file) {
	display = '<img src="'+file+'" width="'+width+'" height="'+height+'"/>';
	$.modal(display,{minHeight:height+20,minWidth: width+20,onClose: function (dialog) {$('#image_splash').show();$.modal.close();}});
	$('#image_splash').hide();
}

function startGallery() {
  $(".container").wtGridGallery({
		num_col:4,
		num_row:2,
		screen_width:550,
		screen_height:435,
		item_width:75,
		item_height:75,
		item_margin:8,
		display_number:true,
		display_playbutton:true,
		display_dbuttons:true,
		display_advbuttons:false,
		display_textbutton:false,
		display_downloadbutton:false,
		display_tooltip:false,
		display_caption:false,
		display_timer:false,
		display_gallery_info:false,
		effect:"fade",
		transition_speed:700,
		easing:"",
		text_effect:"fade",
		text_sync:true,
		text_on:false,
		cpanel_float:true,
		cpanel_mouseover:true,
		auto_scale:true,
		cont_nav:false,
		auto_rotate:true,
		delay:5000,
		initial_open:false,
		selected_category:1,
		selected_image:1
  });
}

function startMultiArea() {

	//When page loads...
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabs li").click(function() {

		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});
}

function mapCoverRemove(){
	if($('#map_cover img').length > 0){
		$('#map_cover img:last').detach();
		setTimeout('mapCoverRemove();',2000);
	}
	else {
		$('#map_cover').detach();
	}
}

/*
 * SimpleModal 1.4.1 - jQuery Plugin
 * http://www.ericmmartin.com/projects/simplemodal/
 * Copyright (c) 2010 Eric Martin (http://twitter.com/ericmmartin)
 * Dual licensed under the MIT and GPL licenses
 * Revision: $Id: jquery.simplemodal.js 261 2010-11-05 21:16:20Z emartin24 $
 */
(function(d){var k=d.browser.msie&&parseInt(d.browser.version)===6&&typeof window.XMLHttpRequest!=="object",m=d.browser.msie&&parseInt(d.browser.version)===7,l=null,f=[];d.modal=function(a,b){return d.modal.impl.init(a,b)};d.modal.close=function(){d.modal.impl.close()};d.modal.focus=function(a){d.modal.impl.focus(a)};d.modal.setContainerDimensions=function(){d.modal.impl.setContainerDimensions()};d.modal.setPosition=function(){d.modal.impl.setPosition()};d.modal.update=function(a,b){d.modal.impl.update(a,
b)};d.fn.modal=function(a){return d.modal.impl.init(this,a)};d.modal.defaults={appendTo:"body",focus:true,opacity:50,overlayId:"simplemodal-overlay",overlayCss:{},containerId:"simplemodal-container",containerCss:{},dataId:"simplemodal-data",dataCss:{},minHeight:null,minWidth:null,maxHeight:null,maxWidth:null,autoResize:false,autoPosition:true,zIndex:1E3,close:true,closeHTML:'<a class="modalCloseImg" title="Close"></a>',closeClass:"simplemodal-close",escClose:true,overlayClose:false,position:null,
persist:false,modal:true,onOpen:null,onShow:null,onClose:null};d.modal.impl={d:{},init:function(a,b){var c=this;if(c.d.data)return false;l=d.browser.msie&&!d.boxModel;c.o=d.extend({},d.modal.defaults,b);c.zIndex=c.o.zIndex;c.occb=false;if(typeof a==="object"){a=a instanceof jQuery?a:d(a);c.d.placeholder=false;if(a.parent().parent().size()>0){a.before(d("<span></span>").attr("id","simplemodal-placeholder").css({display:"none"}));c.d.placeholder=true;c.display=a.css("display");if(!c.o.persist)c.d.orig=
a.clone(true)}}else if(typeof a==="string"||typeof a==="number")a=d("<div></div>").html(a);else{alert("SimpleModal Error: Unsupported data type: "+typeof a);return c}c.create(a);c.open();d.isFunction(c.o.onShow)&&c.o.onShow.apply(c,[c.d]);return c},create:function(a){var b=this;f=b.getDimensions();if(b.o.modal&&k)b.d.iframe=d('<iframe src="javascript:false;"></iframe>').css(d.extend(b.o.iframeCss,{display:"none",opacity:0,position:"fixed",height:f[0],width:f[1],zIndex:b.o.zIndex,top:0,left:0})).appendTo(b.o.appendTo);
b.d.overlay=d("<div></div>").attr("id",b.o.overlayId).addClass("simplemodal-overlay").css(d.extend(b.o.overlayCss,{display:"none",opacity:b.o.opacity/100,height:b.o.modal?f[0]:0,width:b.o.modal?f[1]:0,position:"fixed",left:0,top:0,zIndex:b.o.zIndex+1})).appendTo(b.o.appendTo);b.d.container=d("<div></div>").attr("id",b.o.containerId).addClass("simplemodal-container").css(d.extend(b.o.containerCss,{display:"none",position:"fixed",zIndex:b.o.zIndex+2})).append(b.o.close&&b.o.closeHTML?d(b.o.closeHTML).addClass(b.o.closeClass):
"").appendTo(b.o.appendTo);b.d.wrap=d("<div></div>").attr("tabIndex",-1).addClass("simplemodal-wrap").css({height:"100%",outline:0,width:"100%"}).appendTo(b.d.container);b.d.data=a.attr("id",a.attr("id")||b.o.dataId).addClass("simplemodal-data").css(d.extend(b.o.dataCss,{display:"none"})).appendTo("body");b.setContainerDimensions();b.d.data.appendTo(b.d.wrap);if(k||l)b.fixIE()},bindEvents:function(){var a=this;d("."+a.o.closeClass).bind("click.simplemodal",function(b){b.preventDefault();a.close()});
a.o.modal&&a.o.close&&a.o.overlayClose&&a.d.overlay.bind("click.simplemodal",function(b){b.preventDefault();a.close()});d(document).bind("keydown.simplemodal",function(b){if(a.o.modal&&b.keyCode===9)a.watchTab(b);else if(a.o.close&&a.o.escClose&&b.keyCode===27){b.preventDefault();a.close()}});d(window).bind("resize.simplemodal",function(){f=a.getDimensions();a.o.autoResize?a.setContainerDimensions():a.o.autoPosition&&a.setPosition();if(k||l)a.fixIE();else if(a.o.modal){a.d.iframe&&a.d.iframe.css({height:f[0],
width:f[1]});a.d.overlay.css({height:f[0],width:f[1]})}})},unbindEvents:function(){d("."+this.o.closeClass).unbind("click.simplemodal");d(document).unbind("keydown.simplemodal");d(window).unbind("resize.simplemodal");this.d.overlay.unbind("click.simplemodal")},fixIE:function(){var a=this,b=a.o.position;d.each([a.d.iframe||null,!a.o.modal?null:a.d.overlay,a.d.container],function(c,h){if(h){var g=h[0].style;g.position="absolute";if(c<2){g.removeExpression("height");g.removeExpression("width");g.setExpression("height",
'document.body.scrollHeight > document.body.clientHeight ? document.body.scrollHeight : document.body.clientHeight + "px"');g.setExpression("width",'document.body.scrollWidth > document.body.clientWidth ? document.body.scrollWidth : document.body.clientWidth + "px"')}else{var e;if(b&&b.constructor===Array){c=b[0]?typeof b[0]==="number"?b[0].toString():b[0].replace(/px/,""):h.css("top").replace(/px/,"");c=c.indexOf("%")===-1?c+' + (t = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"':
parseInt(c.replace(/%/,""))+' * ((document.documentElement.clientHeight || document.body.clientHeight) / 100) + (t = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"';if(b[1]){e=typeof b[1]==="number"?b[1].toString():b[1].replace(/px/,"");e=e.indexOf("%")===-1?e+' + (t = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft) + "px"':parseInt(e.replace(/%/,""))+' * ((document.documentElement.clientWidth || document.body.clientWidth) / 100) + (t = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft) + "px"'}}else{c=
'(document.documentElement.clientHeight || document.body.clientHeight) / 2 - (this.offsetHeight / 2) + (t = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"';e='(document.documentElement.clientWidth || document.body.clientWidth) / 2 - (this.offsetWidth / 2) + (t = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft) + "px"'}g.removeExpression("top");g.removeExpression("left");g.setExpression("top",
c);g.setExpression("left",e)}}})},focus:function(a){var b=this;a=a&&d.inArray(a,["first","last"])!==-1?a:"first";var c=d(":input:enabled:visible:"+a,b.d.wrap);setTimeout(function(){c.length>0?c.focus():b.d.wrap.focus()},10)},getDimensions:function(){var a=d(window);return[d.browser.opera&&d.browser.version>"9.5"&&d.fn.jquery<"1.3"||d.browser.opera&&d.browser.version<"9.5"&&d.fn.jquery>"1.2.6"?a[0].innerHeight:a.height(),a.width()]},getVal:function(a,b){return a?typeof a==="number"?a:a==="auto"?0:
a.indexOf("%")>0?parseInt(a.replace(/%/,""))/100*(b==="h"?f[0]:f[1]):parseInt(a.replace(/px/,"")):null},update:function(a,b){var c=this;if(!c.d.data)return false;c.d.origHeight=c.getVal(a,"h");c.d.origWidth=c.getVal(b,"w");c.d.data.hide();a&&c.d.container.css("height",a);b&&c.d.container.css("width",b);c.setContainerDimensions();c.d.data.show();c.o.focus&&c.focus();c.unbindEvents();c.bindEvents()},setContainerDimensions:function(){var a=this,b=k||m,c=a.d.origHeight?a.d.origHeight:d.browser.opera?
a.d.container.height():a.getVal(b?a.d.container[0].currentStyle.height:a.d.container.css("height"),"h");b=a.d.origWidth?a.d.origWidth:d.browser.opera?a.d.container.width():a.getVal(b?a.d.container[0].currentStyle.width:a.d.container.css("width"),"w");var h=a.d.data.outerHeight(true),g=a.d.data.outerWidth(true);a.d.origHeight=a.d.origHeight||c;a.d.origWidth=a.d.origWidth||b;var e=a.o.maxHeight?a.getVal(a.o.maxHeight,"h"):null,i=a.o.maxWidth?a.getVal(a.o.maxWidth,"w"):null;e=e&&e<f[0]?e:f[0];i=i&&i<
f[1]?i:f[1];var j=a.o.minHeight?a.getVal(a.o.minHeight,"h"):"auto";c=c?a.o.autoResize&&c>e?e:c<j?j:c:h?h>e?e:a.o.minHeight&&j!=="auto"&&h<j?j:h:j;e=a.o.minWidth?a.getVal(a.o.minWidth,"w"):"auto";b=b?a.o.autoResize&&b>i?i:b<e?e:b:g?g>i?i:a.o.minWidth&&e!=="auto"&&g<e?e:g:e;a.d.container.css({height:c,width:b});a.d.wrap.css({overflow:h>c||g>b?"auto":"visible"});a.o.autoPosition&&a.setPosition()},setPosition:function(){var a=this,b,c;b=f[0]/2-a.d.container.outerHeight(true)/2;c=f[1]/2-a.d.container.outerWidth(true)/
2;if(a.o.position&&Object.prototype.toString.call(a.o.position)==="[object Array]"){b=a.o.position[0]||b;c=a.o.position[1]||c}else{b=b;c=c}a.d.container.css({left:c,top:b})},watchTab:function(a){var b=this;if(d(a.target).parents(".simplemodal-container").length>0){b.inputs=d(":input:enabled:visible:first, :input:enabled:visible:last",b.d.data[0]);if(!a.shiftKey&&a.target===b.inputs[b.inputs.length-1]||a.shiftKey&&a.target===b.inputs[0]||b.inputs.length===0){a.preventDefault();b.focus(a.shiftKey?"last":
"first")}}else{a.preventDefault();b.focus()}},open:function(){var a=this;a.d.iframe&&a.d.iframe.show();if(d.isFunction(a.o.onOpen))a.o.onOpen.apply(a,[a.d]);else{a.d.overlay.show();a.d.container.show();a.d.data.show()}a.o.focus&&a.focus();a.bindEvents()},close:function(){var a=this;if(!a.d.data)return false;a.unbindEvents();if(d.isFunction(a.o.onClose)&&!a.occb){a.occb=true;a.o.onClose.apply(a,[a.d])}else{if(a.d.placeholder){var b=d("#simplemodal-placeholder");if(a.o.persist)b.replaceWith(a.d.data.removeClass("simplemodal-data").css("display",
a.display));else{a.d.data.hide().remove();b.replaceWith(a.d.orig)}}else a.d.data.hide().remove();a.d.container.hide().remove();a.d.overlay.hide();a.d.iframe&&a.d.iframe.hide().remove();setTimeout(function(){a.d.overlay.remove();a.d={}},10)}}}})(jQuery);

