var RICH = new Object();
RICH.stock = new Object();
RICH.external_url = null;



function goToGalleryFromPhoto(){
	if(!RICH.external_url){
		RICH.external_url = "http://www.photoboxgallery.com/richmondparklondon/collection?album_id=104268779";
	}
	pageTracker._trackPageview('/external/photoboxgallery/collection/photo');
	var pbox = window.open(RICH.external_url);
}

function buyMessages(){
	var messages = new Array();
	messages[0] = "Would I look good in your home?";
	messages[1] = "Put me on your lovely wall please!";
	messages[2] = "Make a local photographer very happy";
	messages[3] = "Put some local art on your walls!";
	messages[4] = "Would this make an original gift?";
	messages[5] = "A local photo from a local photographer";		
	
	messages.sort( function() {return 0.5 - Math.random()});
	
	if(document.getElementById('photo_message').innerHTML == ""){
		document.getElementById('photo_message').innerHTML = messages[0];
	}

}



var today = new Date();
var expires = new Date(today.getTime() + (56 * 86400000));

function Set_Cookie(name,value,expires,path,domain,secure) {
	domain = ".richmondparklondon.co.uk";
	path = "/";
    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") +
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");
}

function Get_Cookie(name) {
    var start = document.cookie.indexOf(name+"=");
    var len = start+name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
    if (start == -1) return null;
    var end = document.cookie.indexOf(";",len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
}


function Delete_Cookie(name,path,domain) {
    if (Get_Cookie(name)) document.cookie = name + "=" +
        ( (path) ? ";path=" + path : "") +
        ( (domain) ? ";domain=" + domain : "") +
        ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
/////// HISTORY ////////////////////


function getStockCookie(){
	var stock = RICH.stock;
	stock.cookie = Get_Cookie('stock');
	
	if(stock.cookie != null && stock.cookie != ""){
		// if cookie is used, eval JSON
		stock.data = eval('('+stock.cookie+')');
	}else{
		// create space for data
		stock.data = {};
		stock.data.files = new Array();
	}
}

function addToStockCookie(file_name){
	getStockCookie();
	var stock = RICH.stock;
	var okToSave = true;
	var files = stock.data.files;
	// add latest (if not duplicate)
	if(files && files.length>=1){
		for(var i=0;i<files.length;i++){
			if(files[i] == file_name){
				okToSave = false;
			}
		}
	}
	if(okToSave){
		files.unshift(file_name);
	}		
	stock.cookie = stock.data.toJSONString();
	//alert(stock.cookie);
	Set_Cookie("stock",stock.cookie,expires,'/');
}


function clearStockCookie(){
	Set_Cookie("stock","",expires,'/');
	document.location.reload();
}


//////////////// END HISTORY //////////////	


// handles hover sub menus in IE
startList = function() {
	if (document.all&&document.getElementById && document.getElementById("nav_ul")) {
		var navRoot = document.getElementById("nav_ul");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}


function addLoadListener(fn){ 
	if (typeof window.addEventListener != 'undefined') { 
		window.addEventListener('load', fn, false); 
	}else if (typeof document.addEventListener != 'undefined'){ 
		document.addEventListener('load', fn, false); 
 	}else if (typeof window.attachEvent != 'undefined'){ 
		window.attachEvent('onload', fn); 
	}else{ 
		var oldfn = window.onload; 
		if (typeof window.onload != 'function'){ 
			window.onload = fn; 
		}else{ 
			window.onload = function(){
				oldfn();
				fn();
			}; 
   		}
	}
}

addLoadListener(startList);



//////////////////// JSON LIB ///////////////////

/*
json.js
2006-04-28

This file adds these methods to JavaScript:

object.toJSONString()

This method produces a JSON text from an object. The
object must not contain any cyclical references.

array.toJSONString()

This method produces a JSON text from an array. The
array must not contain any cyclical references.

string.parseJSON()

This method parses a JSON text to produce an object or
array. It will return false if there is an error.
*/
(function () {
var m = {
'\b': '\\b',
'\t': '\\t',
'\n': '\\n',
'\f': '\\f',
'\r': '\\r',
'"' : '\\"',
'\\': '\\\\'
},
s = {
array: function (x) {
var a = ['['], b, f, i, l = x.length, v;
for (i = 0; i < l; i += 1) {
v = x[i];
f = s[typeof v];
if (f) {
v = f(v);
if (typeof v == 'string') {
if (b) {
a[a.length] = ',';
}
a[a.length] = v;
b = true;
}
}
}
a[a.length] = ']';
return a.join('');
},
'boolean': function (x) {
return String(x);
},
'null': function (x) {
return "null";
},
number: function (x) {
return isFinite(x) ? String(x) : 'null';
},
object: function (x) {
if (x) {
if (x instanceof Array) {
return s.array(x);
}
var a = ['{'], b, f, i, v;
for (i in x) {
v = x[i];
f = s[typeof v];
if (f) {
v = f(v);
if (typeof v == 'string') {
if (b) {
a[a.length] = ',';
}
a.push(s.string(i), ':', v);
b = true;
}
}
}
a[a.length] = '}';
return a.join('');
}
return 'null';
},
string: function (x) {
if (/["\\\x00-\x1f]/.test(x)) {
x = x.replace(/([\x00-\x1f\\"])/g, function(a, b) {
var c = m[b];
if (c) {
return c;
}
c = b.charCodeAt();
return '\\u00' +
Math.floor(c / 16).toString(16) +
(c % 16).toString(16);
});
}
return '"' + x + '"';
}
};
Object.prototype.toJSONString = function () {
return s.object(this);
};
Array.prototype.toJSONString = function () {
return s.array(this);
};
})();

String.prototype.parseJSON = function () {
try {
return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(
this.replace(/"(\\.|[^"\\])*"/g, ''))) &&
eval('(' + this + ')');
} catch (e) {
return false;
}
};
//////////////// END JSON LIB //////////////////

String.prototype.ucFirst = function () {
   var firstLetter = this.substr(0,1).toUpperCase()
   return this.substr(0,1).toUpperCase() + this.substr(1,this.length);
}	