//initialisation function

if(typeof Array.prototype.push!='function'){Array.prototype.push=function(v){var i=this.length>>>0,j=0;while(j<arguments.length){this[i++]=arguments[j++];}
return(this.length=i);};}

if(!Object.prototype.hasOwnProperty){Object.prototype.hasOwnProperty=function(pty){return(typeof this[pty]!="undefined"&&(this.constructor&&this.constructor.prototype&&this.constructor.prototype[pty]!==this[pty]));};}

var bool,
f = {
	onloadArray : [],
	mapContentArray : [],
	points : {},
	isIE : function () {
		var __isIE = false;
		
		/*@cc_on
  			@if (@_win32)
				__isIE = true;
   			@end
		@*/
		
		return __isIE;
	},
	
	addOnloadEvent : function (func, order) {
		var that = this;
		var arr = that.onloadArray;
		arr.push(func);
		window.onload = function () {
			for (var i = Number(0); i < arr.length; i++){
				arr[i]();
			}
		};
	},
	
	$ : function (id){
		return document.getElementById(id);
	},
	
	clearChildren : function (n){
		while (n.firstChild){
			n.removeChild(n.firstChild)
		}
		return n;
	},
	
	getElementsByClassName : function (par, str, tag) {
		var tag = (!tag) ? "*" : tag ;
		var __re, __el, __arr = (tag == "*" && par.all) ? par.all : par.getElementsByTagName(tag), __holder = [];
		
		str = str.replace(/\-/g, "\\-");
		__re = new RegExp("(^|\\s)" + str + "(\\s|$)");
		
		for (var i = Number(0); i < __arr.length; i++) {
			__el = __arr[i];
			if (__re.test(__el.className)) {
				__holder.push(__el);
			}
		}
		
		return (__holder);
	},
	
	getElementContents : function (par, str, o) {
		/* args 
		par is the DOM object that contains the object you're searching for 
		type 	: 				DOM element
		ie 		: 				{document | f.$("div")}
		
		str is the search term
		type 	: 				String
		ie		: 				{"h3" | "class-name" | "div"}
		
		o is an object which contains properties that are contextual to the search term
			o.pos 	:				as both getElementsByTagName and getElementsByClassName return
									arrays this property allows you to grab an object from a
									position within the zero-indexed array. If this value is not
									existant in the object then the full array is returned. You 
									can explicitly request the full array by including the string "all"
			type	:				String, Number
			ie		:				{undefined | [0-9] | "all"}
		
			o.type	:				is the type of element you want to search
			type	:				String
			ie		:				{"tag" | "class" | "id"}
			
			o.tag :					is an optional property of the object that's used for the 
									getElementsByClassName method which allows you to shorten the "depth"
									of the search - from all elements in the page to a sub node. Must 
									be a tag name.
			type	:				String
			ie		:				{"div" | "span"}
		
		*/
		var __obj, that = this;
		
		switch (o.type) {
			case "tag":
			__obj = (o.pos == undefined || o.pos == "all") ? par.getElementsByTagName(str) : par.getElementsByTagName(str)[o.pos];
			break;
			
			case "class":
			__obj = (o.pos == undefined || o.pos == "all") ? that.getElementsByClassName(par, str, o.tag) : that.getElementsByClassName(par, str, o.tag)[o.pos];
			break;
			
			case "id":
			__obj = par.$(str);
			break;
		}
		
		return __obj;
	}
};
  
var FC = {
		
	detectMacXFF: function() {
		var userAgent = navigator.userAgent.toLowerCase();
		if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
			return true;
		}
		
	},
		
	revealLogin: function() {
		$('.tools ul:first').append('<li class="reveal last"><a href="#"><img src="/images/registration/icon-login.gif" width="13" height="14" alt="login" /></a></li>');
		
		$('.tools .reveal a').bind("click", function() {
			if(!($(this).hasClass('close'))) {
				var h= $('.tools-panel .padding').height();
				
				$('.tools-panel .padding:first').animate({
					height: h+20
				}, function() {
					$('.login-overlay').css('display','block');
				});
				
				$('.tools .reveal a img').attr({
					src: '/images/registration/icon-close.gif',
					width: '13',
					height: '14',
					alt: 'Close'
				});
				
				$('.tools .reveal a').addClass('close');
				
				
				return false;
			}
			else {
				$('.login-overlay').css('display','none');
				var h= $('.tools-panel .padding').height();
				$('.tools-panel .padding').animate({height: h-20});
				
				$('.tools .close').removeClass('close');
				$('.tools .reveal img').attr({
						src: '/images/registration/icon-login.gif',
						width: '13',
						height: '14',
						alt: 'Login'
				 });
				return false;
			}
		});
	}
}

$(document).ready(function(){
	if($('.tools .login-overlay').length){FC.revealLogin();}
});