/*
	
	Copyright 2007 Artlogic Media Limited - http://www.artlogic.net/
	All rights reserved.

*/


//	COOKIE FUNCTIONS


	function setCookie(cookieName,cookieValue,nDays,path) {
		var today = new Date();
		var expire = new Date();
		if (nDays==null || nDays==0) {
			nDays=1;
		}
		expire.setTime(today.getTime() + 3600000*24*nDays);
		if (typeof path=="undefined") {
			document.cookie = cookieName+"="+escape(cookieValue)+";expires="+expire.toGMTString();
		} else {
			document.cookie = cookieName+"="+escape(cookieValue)+";expires="+expire.toGMTString()+";path="+escape(path);
		}
	}

	function readCookie(cookieName) {
		var theCookie=""+document.cookie;
		var ind=theCookie.indexOf(cookieName);
		if (ind==-1 || cookieName=="") {
			return ""; 
		}
		var ind1=theCookie.indexOf(';',ind);
		if (ind1==-1) {
			ind1=theCookie.length;
		}
		return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
	}



//	ARE COOKIES ENABLED?

	var cookiesEnabled = true;
	
	setCookie("cookiesEnabled", "true", 30, "/");
	if (readCookie(cookiesEnabled) == "" ) {
		cookiesEnabled = false;
	}




//	PAGE FUNCTIONS

	doOnLoadOnResize = function() {

		
		resizePage();
	
	}
	
	



//	FUNCTIONS WHICH HANDLE THE WINDOW RESIZE

	var resizePage = function() {
		if (cookiesEnabled) {
			document.body.style.overflow = "hidden";
			var winW = (document.body.clientWidth) ? document.body.clientWidth : window.innerWidth;
			var winH = (document.body.clientHeight) ? document.body.clientHeight : window.innerHeight;
			document.body.style.overflow = "visible";
			var offsetHorizontal = 100;
			var offsetVertical = 20
			/*	Note: Firefox does not correctly calculate the inner height (it only calculates the *used* content), so we just test for the width. */
			var winSize = (winW < 1200 + offsetHorizontal) ? "small" : "large";
			var prevWinSize = readCookie("winSize");		
			if (prevWinSize != winSize) {
				setCookie("winSize", winSize, 30, "/");
				document.body.style.visibility = "hidden";
				document.location.href = document.location.href;
		}
		}
	}





//	BROWSER DETECT

	var browser = {
	
		app_name: navigator.appName,
		version: parseInt(navigator.appVersion),
		agent: navigator.userAgent.toLowerCase(),
		web_kit_version: -1,
		
		unsupported: function() {
			var t;
			if (this.safari && this.web_kit_version < 400) {
				t = 'safari';
			} else if (this.mac && this.ie) {
				t = 'ie_mac';
			}
			if (t) {
				this.redirect(t);
			}
		},
		
		detect: function() {
			
			this.safari = this.agent.indexOf('safari') > -1;
			this.ie = this.agent.indexOf('msie') > -1
			this.opera = this.agent.indexOf('opera') > -1;
			this.firefox = this.agent.indexOf('firefox') > -1;
			this.iphone = this.agent.indexOf('iphone') > -1;
			
			this.win = this.agent.indexOf('win') > -1;
			this.mac = this.agent.indexOf('mac') > -1;
			
			if (this.safari && this.agent.indexOf('version/')) {
				this.version = parseInt(this.agent.split('version/')[1].split(' ')[0]);
			} else if (this.safari) {
				this.version = -1;
			}
			
			if (this.safari) {
				try {
					this.web_kit_version = parseInt(this.agent.split('applewebkit/')[1].split('.')[0].split(' ')[0]);
				} catch (e) {
					// the format may have changed. We tried...
				}
			}
			// test for unsupported
			this.unsupported();
			
		},
		
		redirect: function(t) {
			document.location.href = 'unsupported_browser/?browser=' + t;
		}
	
	
	}
	
	browser.detect();