
// JavaScript Document
var NavControl = 
{
    STACK : new Array(),
    
	clickNavOption : function(layerHeight, layerName, linker)
	{
		   /* Nav Panel : News Letter : Load Required Image : jh/apr11 */
                try {
                var f=document.getElementById("nl_image_set");
                if ( f.hasAttribute("element_to_load"))
                {
                var ff=f.getAttribute("element_to_load");
                f.src=ff;
                }
                } catch ( noImageReferenceLocatedException ) {

                }      

	
            var keepOpen = false;
            
            // Check if the contact is open and turn off if it is
            if(NavControl.STACK['extra-panel-contact'].style.display == 'block')
            {
                NavControl.STACK['extra-panel-contact'].style.display = 'none';
                NavControl.STACK['contact-link'].className = 'top-nav';
                if(layerName != 'extra-panel-contact')
                {
                    keepOpen = true;
                }
            }
            
            // Check if the newsletters is open and turn off if it is
            if(NavControl.STACK['extra-panel-newsletter'].style.display == 'block')
            {
                NavControl.STACK['extra-panel-newsletter'].style.display = 'none';
                NavControl.STACK['newsletter-link'].className = 'top-nav';
                if(layerName != 'extra-panel-newsletter')
                {
                    keepOpen = true;
                }
                
                       
                
            }
                
			// Check to see if we have the nav list open or not
			if(NavControl.STACK['extra-panel-outer'] && NavControl.STACK['extra-panel-outer'].style.display == 'none')
			{
				
				// Now turn the appropriate layer on that we want
				NavControl.STACK[layerName].style.display = 'block';
           		NavControl.STACK[linker].className = 'top-nav-on';
                
				var grower = window.setInterval(function()
														 {
                                                             	if(!NavControl.STACK['extra-panel-outer'].style.height)
                                                                {
																	NavControl.STACK['extra-panel-outer'].style.height = '0px';
                                                                }
                                                                var elementHeight = parseInt(NavControl.STACK['extra-panel-outer'].style.height);
                                                                
																if(parseInt(elementHeight) < parseInt(layerHeight))
																{
																	NavControl.STACK['extra-panel-outer'].style.display = 'block';
                                                                    
                                                                    if(parseInt(elementHeight)+40 <  parseInt(layerHeight))
                                                                    {
                                                                      	elementHeight = parseInt(elementHeight)+40;  
                                                                    }
                                                                    else
                                                                    {
                                                                        elementHeight = parseInt(layerHeight);  
                                                                    }
                                                                    
																	NavControl.STACK['extra-panel-outer'].style.height = (parseInt(elementHeight)) + 'px';
																}
																else
																{
                                                                    elementHeight = layerHeight;
                                                                    NavControl.STACK['extra-panel-outer'].style.height = layerHeight + 'px';
																	window.clearInterval(grower);
																}
														 }, 60);
			}
			else
			{
                if(!keepOpen)
                {
            		NavControl.STACK[linker].className = 'top-nav';
                    var minimiser = window.setInterval(function()
                                                                {
                                                                    var elementHeight = parseInt(NavControl.STACK['extra-panel-outer'].style.height);
                                                                    
                                                                    if((parseInt(elementHeight) > 0 && parseInt(elementHeight) >= 40) && minimiser)
                                                                    { 
                                                                        NavControl.STACK['extra-panel-outer'].style.height = (parseInt(elementHeight) - 40) + 'px';
                                                                    }
                                                                    else if((parseInt(elementHeight) <= 0 || parseInt(elementHeight) <= 40) && minimiser)
                                                                    {
                                                                        elementHeight = 0;
                                                                        NavControl.STACK['extra-panel-outer'].style.height = elementHeight + 'px';
                                                                        NavControl.STACK['extra-panel-outer'].style.display = 'none';
                                                                        window.clearInterval(minimiser);
                                                                    }
                                                                }, 60);
                }
                else
                {
                    // Now turn the appropriate layer on that we want
            		NavControl.STACK[linker].className = 'top-nav-on';
                    NavControl.STACK['extra-panel-outer'].style.height = parseInt(layerHeight) + 'px';
                    NavControl.STACK[layerName].style.display = 'block';  
                }
			}
	},
    
	closeNavItem : function()
	{
                NavControl.STACK['sitemap-link'].className = 'top-nav';
                NavControl.STACK['contact-link'].className = 'top-nav';
                NavControl.STACK['newsletter-link'].className = 'top-nav';
				var minimiser = window.setInterval(function()
															{
																var elementHeight = parseInt(NavControl.STACK['extra-panel-outer'].style.height);
																
																if((parseInt(elementHeight) > 0 && parseInt(elementHeight) >= 40) && minimiser)
																{ 
																	NavControl.STACK['extra-panel-outer'].style.height = (parseInt(elementHeight) - 45) + 'px';
																}
																else if((parseInt(elementHeight) <= 0 || parseInt(elementHeight) <= 40) && minimiser)
																{
                                                                    elementHeight = 0;
                                                                    NavControl.STACK['extra-panel-outer'].style.height = elementHeight + 'px';
																	NavControl.STACK['extra-panel-outer'].style.display = 'none';
																	window.clearInterval(minimiser);
																}
															}, 60);
	},
    
    sendNewsletter : function()
    {
    	var email = NavControl.STACK['email3'].value;
    	var url = "/newsletter.php?email3=" + email;
		this.Ajax(url);
    },
    
    sendContact : function()
    {
    	var name = Base64.encode(NavControl.STACK['contactname'].value);
    	var email = Base64.encode(NavControl.STACK['contactemail'].value);
    	var message = Base64.encode(NavControl.STACK['contactmessage'].value);
        var url = "/contactSystem/site-wide-contact.php?name=" + name + "&email=" + email + "&message=" + message;
		this.Ajax(url);
    },
    
    __handler 	: null,
    
    Ajax : function( URL, POST, postAjaxFunction ) {
		if ( typeof postAjaxFunction == 'undefined' || postAjaxFunction == '' ) {
			postAjaxFunction = 'postAjax(response)';
		}
		try {
			if ( SendRightFeedback.__handler ) SendRightFeedback.__handler.abort() ;
			SendRightFeedback.__handler = ( window.XMLHttpRequest ) ? new XMLHttpRequest() : ( window.ActiveXObject ) ? new ActiveXObject("Microsoft.XMLHTTP") : null ;
			if ( SendRightFeedback.__handler ) {
				SendRightFeedback.__handler.onreadystatechange = function() { SendRightFeedback.ParseJax( SendRightFeedback.__handler, postAjaxFunction ) ;
			}
			if ( POST != '' && POST !=null && POST != "undefined" ) {
				SendRightFeedback.__handler.open("POST", URL, true);
				SendRightFeedback.__handler.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				SendRightFeedback.__handler.setRequestHeader("Content-length", POST.length);
				SendRightFeedback.__handler.setRequestHeader("Connection", "close");
				SendRightFeedback.__handler.send(POST);
			} else {
				SendRightFeedback.__handler.open("GET", URL, true);
				SendRightFeedback.__handler.send(null);
			}
		}
		} catch (ee ){}
	},

	ParseJax : function( handler, postAjaxFunction ) {
		try {
		if ( handler ) {
			if ( handler.readyState == 4 && handler.status == 200 ) {
				if ( handler.responseText != '' ) {
					eval(handler.responseText);
				}
			}
		}
		} catch (ee ){}
	},
    
    setBack : function()
    {
    	if(document.body)
        {
        	document.body.style.backgroundPosition = '50% ' + (parseInt($(window).height()) - 960)+ "px";
        }
        else
        {
        	document.documentElement.style.backgroundPosition = '50% ' + $(window).height() + "px";
        }
    	var height = $(document).height();
    	NavControl.STACK['lions'].style.height = parseInt(height) + 'px';
    },
    
	setStack : function()
	{
		NavControl.STACK['document'] = document;
		NavControl.STACK['extra-panel-outer'] = NavControl.STACK['document'].getElementById('extra-panel-outer');
		NavControl.STACK['extra-panel-contact'] = NavControl.STACK['document'].getElementById('extra-panel-contact');
		NavControl.STACK['extra-panel-newsletter'] = NavControl.STACK['document'].getElementById('extra-panel-newsletter');
		NavControl.STACK['contactname'] = NavControl.STACK['document'].getElementById('contactname');
		NavControl.STACK['contactemail'] = NavControl.STACK['document'].getElementById('contactemail');
		NavControl.STACK['contactmessage'] = NavControl.STACK['document'].getElementById('contactmessage');
		NavControl.STACK['email3'] = NavControl.STACK['document'].getElementById('email3');
		NavControl.STACK['sitemap-link'] = NavControl.STACK['document'].getElementById('sitemap-link');
		NavControl.STACK['contact-link'] = NavControl.STACK['document'].getElementById('contact-link');
		NavControl.STACK['newsletter-link'] = NavControl.STACK['document'].getElementById('newsletter-link');
		NavControl.STACK['lions'] = NavControl.STACK['document'].getElementById('lions');
	}

};
 
var Base64 = {
 
	// private property
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
 
	// public method for encoding
	encode : function (input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;
 
		input = Base64._utf8_encode(input);
 
		while (i < input.length) {
 
			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);
 
			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;
 
			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}
 
			output = output +
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
 
		}
 
		return output;
	},
 
	// public method for decoding
	decode : function (input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;
 
		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
 
		while (i < input.length) {
 
			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));
 
			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;
 
			output = output + String.fromCharCode(chr1);
 
			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}
 
		}
 
		output = Base64._utf8_decode(output);
 
		return output;
 
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}


function swithnavtop(img, imgpath)
{
	img.src = 'http://images.londontown.com/images/site-wide/' + imgpath + '.gif';	
}

if(window.addEventListener)
{
	window.addEventListener('load', function(){NavControl.setStack();NavControl.setBack();}, true);
	window.addEventListener('resize', function(){NavControl.setBack();}, true);
}
else
{
	window.attachEvent('onload', function(){NavControl.setStack();NavControl.setBack();});
	window.attachEvent('onresize', function(){NavControl.setBack();});
}

function preload(arrayOfImages) {
    $(arrayOfImages).each(function(){
        $('<img/>')[0].src = this;
    });
}

$(document).ready(function(){
	    $(".scroll").click(function(event){
	        //prevent the default action for the click event
	        event.preventDefault();
	 
	        //get the full url - like mysitecom/index.htm#home
	        var full_url = this.href;
	 
	        //split the url by # and get the anchor target name - home in mysitecom/index.htm#home
	        var parts = full_url.split("#");
	        var trgt = parts[1];
            
	        //get the top offset of the target anchor
	        var target_offset = $("#"+trgt).offset();
	        var target_top = target_offset.top - 60;
	 
	        //goto that anchor by setting the body scroll top to anchor top
	        $('html, body').animate({scrollTop:target_top}, 2200);
            
            $('html, body').clearQueue();
	    });
	});
