// ________________________________________________________
// Get position
function __getPosition(e){
	var left = 0;
	var top = 0;
	while(e.offsetParent !== undefined && e.offsetParent !== null){
		left += e.offsetLeft + (e.clientLeft !== null ? e.clientLeft : 0);
		top += e.offsetTop + (e.clientTop !== null ? e.clientTop : 0);
		e = e.offsetParent;
	}
	var arrayPosition = [left,top];
	return arrayPosition;
}

// ________________________________________________________
// Get page size
function __getPageSize(){
	var xScroll, yScroll, pageHeight, pageWidth;
	if(window.innerHeight && window.scrollMaxY){	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	}else if(document.body.scrollHeight > document.body.offsetHeight){
		// All but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	}else{
		// Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if(self.innerHeight){
		// All except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		}else{
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	}else if(document.documentElement && document.documentElement.clientHeight){
		// Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}else if(document.body){
		// Other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	// For small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	}else{ 
		pageHeight = yScroll;
	}
	// For small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	}else{
		pageWidth = windowWidth;
	}
	var arrayPageSize = [pageWidth,pageHeight,windowWidth,windowHeight];
	return arrayPageSize;
}

// ________________________________________________________
// Get page scroll
function __getPageScroll(){
	var xScroll, yScroll;
	if(self.pageYOffset){
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	}else if(document.documentElement && document.documentElement.scrollTop){
		// Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	}else if(document.body){
		// All other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}
	var arrayPageScroll = [xScroll,yScroll];
	return arrayPageScroll;
}

// ________________________________________________________
// Get query string
function __getQueryString(name){
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if(results == null){
		return "";
	}else{
		return decodeURIComponent(results[1].replace(/\+/g, " "));
	}
}

// ________________________________________________________
// Init
function __init(){
	$.browser.msie6 = $.browser.msie && /MSIE 6\.0/i.test(window.navigator.userAgent) && !/MSIE 7\.0/i.test(window.navigator.userAgent);
	
	// External link
	$("a[rel*='external']").click(function(){
		this.target = "_blank";
	});
	
	// Title
	if(!$.browser.msie6){
		$("h2").flash({
			src: '../images/sifr.swf', 
			flashvars: { 
				css: [
					'* { color: #2462aa; }',
					'a { color: #2462aa; text-decoration: none; }',
					].join(' ')
				}
			}, { version: 7 },
			function(htmlOptions){
				htmlOptions.flashvars.txt = this.innerHTML;
				this.innerHTML = '<div>'+this.innerHTML+'</div>';
				var $alt = $(this.firstChild);
				htmlOptions.height = $alt.height();
				htmlOptions.width = $alt.width();
				htmlOptions.wmode = "transparent";
				$alt.addClass('alt');
				$(this)
					.addClass('flash-replaced')
					.prepend($.fn.flash.transform(htmlOptions));						
			}
		);
	}
	
	// Lightbox
	if($(".lightbox").length > 0){
		$(".lightbox").colorbox({
			width: "850px",
			height: "700px",
			onOpen: function(){ $("object").css("visibility", "hidden"); },
			onClosed: function(){ $("object").css("visibility", "visible"); }
		});
	}
	
	// Right
	if($("div#right").length < 1){
		$("#supportingText").css("width", "655px");
	}
}

$(document).ready(function(){
	__init();
});
