// COMMON FILES REQUIRE JQUERY (jquery-latest.js)



/** HELPER FUNCTIONS **/	
	function Is() {
		agent = navigator.userAgent.toLowerCase();
		this.major = parseInt(navigator.appVersion);
		this.minor = parseFloat(navigator.appVersion);
		this.ns = ((agent.indexOf('mozilla') != -1) &&
		(agent.indexOf('spoofer') == -1) &&
		(agent.indexOf('compatible') == -1) &&
		(agent.indexOf('opera') == -1) &&
		(agent.indexOf('webtv') == -1) &&
		(agent.indexOf('hotjava') == -1));
		this.ns2 = (this.ns && (this.major == 2));
		this.ns3 = (this.ns && (this.major == 3));
		this.ns4 = (this.ns && (this.major == 4));
		this.ns6 = (this.ns && (this.major >= 5));
		this.ie = ((agent.indexOf("msie") != -1) &&
		(agent.indexOf("opera") == -1));
		this.ie3 = (this.ie && (this.major < 4));
		this.ie4 = (this.ie && (this.major == 4) &&
		(agent.indexOf("msie 4") != -1));
		this.ie5 = (this.ie && (this.major == 4) &&
		(agent.indexOf("msie 5.") != -1) &&
		(agent.indexOf("msie 5.5") == -1) &&
		(agent.indexOf("mac") == -1));
		this.iem5 = (this.ie && (this.major == 4) &&
		(agent.indexOf("msie 5.") != -1) &&
		(agent.indexOf("mac") != -1));
		this.ie55 = (this.ie && (this.major == 4) &&
		(agent.indexOf("msie 5.5") != -1));
		this.ie6 = (this.ie && (this.major == 4) &&
		(agent.indexOf("msie 6.") != -1));
		this.ie7 = (this.ie && (this.major == 4) &&
		(agent.indexOf("msie 7.0b") != -1));
		this.nsdom = (this.ns4 || this.ns6);
		this.ie5dom = (this.ie5 || this.iem5 || this.ie55);
		this.iedom = (this.ie4 || this.ie5dom || this.ie6);
		this.w3dom = (this.ns6 || this.ie6 ||this.ie7);
}
var is = new Is();
	function load_opacity(affected)
	{
		if($("#opacity")) $("#opacity").remove();
		$("body").append('<div id="opacity"></div>');
		pageSize = getPageSize();
		browserHeight = pageSize[1];
		browserWidth = pageSize[0];
		scrollHeight = parseInt(document.body.scrollHeight);
		scrollWidth = parseInt(document.body.scrollWidth);
		if(scrollHeight > browserHeight) {var width = browserWidth - 20;var opHeight = scrollHeight}
		else {var width = browserWidth; var opHeight = browserHeight;}
		$("#opacity").height(opHeight+"px").width(scrollWidth+"px");
		$("#opacity").show();
		
		$("#opacity").click(function(){
				$("#opacity").hide();
				$("#"+affected).Puff(500,function(){$("#"+affected).remove()});
				//$("body").css('overflow','auto');
			})
		
		$("a.clear_opacity").click(function(){
				$("#opacity").hide();
				$("#"+affected).Puff(500,function(){$("#"+affected).remove()});
				//$("body").css('overflow','auto');
			})
			
	}
	
	function show_loading()
	{
		 $("#loading").top(posY+"px").left(posX+30+"px").fadeIn('fast');
	}	
	
	function hide_loading()
	{
		 $("#loading").fadeOut('fast');
	}


function TB_position(layer,width,height) {
	var pagesize = getPageSize();	
	var arrayPageScroll = getPageScrollTop();
	$("#"+layer).css({left: ((pagesize[0] - width)/2)+"px", top: (arrayPageScroll[1] + ((pagesize[1]-height)/2))+"px" });
}

function getPageScrollTop(){
	var yScrolltop;
	if (self.pageYOffset) {
		yScrolltop = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScrolltop = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScrolltop = document.body.scrollTop;
	}
	arrayPageScroll = new Array('',yScrolltop) 
	return arrayPageScroll;
}

function getPageSize(){
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	
	arrayPageSize = new Array(w,h) 
	return arrayPageSize;
}

var posX = 0;
var posY = 0;

window.document.onmousemove = getMouseXY;

function getMouseXY(e) {

	if(navigator.appName == "Netscape"){
		posX = e.pageX
	 	posY = e.pageY

	} else {
		posX = event.clientX + document.body.scrollLeft
 		posY = event.clientY + document.body.scrollTop
	}

	if (posX <= 0) {posX = 0} 
	if (posY <= 0) {posY = 0}   
 	return true
}

/** END HELPER FUNCTIONS **/



function checkContentHeight()
{
	var div = document.getElementById('content_inner');
	var content_height = $("#content").height();
	var content_width = $("#content").width();
	if(is.ie || is.ie7)
	{
		var h = div.scrollHeight;
		if(h>content_height) $("#content").width(content_width-8+"px")
	}
	else 
	{
		var h= div.clientHeight;
		if(h>content_height) $("#content").width(content_width-8+"px")
	}
	
	
}

var drag_start = 0;
var old_x = 0;

function login_init()
{
	Rounded("div#login","big transparent");
	var pageSize = getPageSize();
	var browserWidth = pageSize[0];
	var browserHeight = pageSize[1];
	
	var topHeight = 			$("#top").height();
	var bottomHeight = 			$("#bottom").height();
	$("#bottom").top(browserHeight-bottomHeight +"px");
	$("#login").top(browserHeight/2 - 150 + "px").left(browserWidth/2-300+"px");
}

function setup_init()
{
	var pageSize = getPageSize();
	var browserWidth = pageSize[0];
	var browserHeight = pageSize[1];
	
	var topHeight = 			$("#top").height();
	var bottomHeight = 			$("#bottom").height();
	
	$("#init_loading").top(browserHeight/2 - 150 + "px").left(browserWidth/2-300+"px");
	$("#bottom").top(browserHeight-bottomHeight +"px");
	$("#login").top(browserHeight/2 - 150 + "px").left(browserWidth/2-300+"px");

	var p = {};
	$("#login").load("/index.php?/ajax/ajax_authenticate/authenticate_login/",p,function(str) { 
		$("#init_loading").DropOutUp(500);
		$("#login").DropInDown(500,function(){
											
		//alert($("#"+section+" .right").width());
		});
	});
}

function setup_window()
{
	load_main();	
}

function load_main()
{
	var pageSize = getPageSize();
			var browserWidth = pageSize[0];
			var browserHeight = pageSize[1];
			var topHeight = 			$("#top").height();
			var bottomHeight = 			$("#bottom").height();
			var totalHeight = 			browserHeight - topHeight - bottomHeight;
			var handleWidth = 			$("#handle").width();
			
			var left_starting_width = 	320;
			var handle_starting_left = left_starting_width;
			var right_starting_width = 	browserWidth-left_starting_width+handleWidth;
			$("#bottom").top(browserHeight-bottomHeight +"px");
			$("#left").width(left_starting_width+"px").top(topHeight + "px").height(totalHeight-10+"px");
			$("#handle").left(handle_starting_left+"px").top(topHeight + "px").height(totalHeight+"px");
			$("#content").left(left_starting_width+"px").width(right_starting_width-2+"px").top(topHeight + "px").height(totalHeight-2+"px");
			
			checkContentHeight();
			
			
			$('#handle').Draggable(
			{
				axis:	'horizontally',
				//containment: Array('0','0','500','0'),
				zIndex: 20,
				onStop: function(){drag_start = 0;},
				onDrag: function(x,y){
					if(drag_start ==0)
					{
						content_left = parseInt($("#content").left());
						content_width = $("#content").width();
						left_width = $("#left").width();
					}
					
					//if(x<=500) 
					left_new_width = x - left_width;
					$("#content").width(content_width - left_new_width+"px").left(content_left+left_new_width+"px");
					$("#left").width(left_width + left_new_width +"px").left(0 +"px");
					drag_start=1;
					old_x = x;
				}
			});	
			
		$("#left").SlideInLeft(500);
		$("#handle").SlideInDown(500);
		$("#content").SlideInRight(500);	
}


function drag_stop()
{
	
}

function open_menu(id)
{
	if($("#"+id).attr('closed') == null || $("#"+id).attr('closed')=='')
	{
		$("#"+id+" .arrow img").src('/images/arrow_open.png');
		$("#"+id+" .information").SlideInUp(500);	
		$("#"+id).attr('closed','open')
	}
	else
	{
		$("#"+id+" .arrow img").src('/images/arrow_closed.png');
		$("#"+id+" .information").SlideOutUp(500);	
		$("#"+id).attr('closed','')
	}
}

//requires jquery and interface base library + fxscrollto plugin
function scroll_to(where)
{
		$("#"+where).ScrollTo(1000,'easeout')
}