var $jq = jQuery.noConflict();

	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($jq("#opacity")) $jq("#opacity").remove();
		$jq("body").append('<div id="opacity"></div>');
		pageSize = getPageSize();
		
		browserHeight = pageSize[1];
		browserWidth = pageSize[0];
		scrollHeight = parseInt(document.body.scrollHeight);
		scrollWidth = parseInt(document.body.scrollWidth);
		scrollTop = getPageScrollTop();
		if(scrollHeight > browserHeight) {var width = browserWidth - 20;var opHeight = scrollHeight}
		else {var width = browserWidth; var opHeight = browserHeight;}
		if(is.ie) $jq("#opacity").height(opHeight+"px").width(scrollWidth+"px");
		else $jq("#opacity").height(opHeight+scrollTop[1]+"px").width(scrollWidth+"px");
		
		$jq("#opacity").show();
		
		$jq("#opacity").click(function(){
				$jq("#opacity").hide();
				$jq("#"+affected).fadeOut(500,function(){
					$jq("#"+affected).remove();
				});
				last_vessel = '';
				//$jq("body").css('overflow','auto');
			})
		
		$jq("a.clear_opacity").click(function(){
				$jq("#opacity").hide();
				$jq("#"+affected).fadeOut(500,function(){
					$jq("#"+affected).remove();
				});
				//$jq("#"+affected).Puff(500,function(){$jq("#"+affected).remove()});
				//$jq("body").css('overflow','auto');
			})
			
	}
	
	function show_loading()
	{
		 TB_position('loading','300','100');
	     TB_position('loading_text','122','26');
		 
		 $jq("#loading").fadeIn('fast');
		 $jq("#loading_text").fadeIn('fast');
	}	
	
	function hide_loading()
	{
		 $jq("#loading").fadeOut('fast');
		 $jq("#loading_text").fadeOut('fast');
	}


function TB_position(layer,width,height) {

	var pagesize = getPageSize();	
	var arrayPageScroll = getPageScrollTop();
	$jq("#"+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
}



function startGallery() {
	var myGallery = new gallery($('myGallery'), {
	timed: false,
	embedLinks: false,
	showArrows: true
});
} 


$jq(document).ready(function(){
	if($jq("#r1 #username").val()!='') $jq("#r1 #username").next().hide();
	if($jq("#r1 #password").val()!='') $jq("#r1 #password").next().hide();

	$jq("#r1 #username").focus(function(){
		$jq(this).next().hide();
	});
	
	$jq("#r1 #username").blur(function(){
		if($jq(this).val()=='') $jq(this).next().show();
	});
	
	$jq("#r1 #password").focus(function(){
		$jq(this).next().hide();
	});
	
	$jq("#r1 #password").blur(function(){
		if($jq(this).val()=='') $jq(this).next().show();
	});
	
	
	$jq("#c1 li a").mouseover(function(){
		var source = $jq(this).children('img').attr('src');
		source = source.replace(/\.jpg/gi,'_hl.jpg');
		$jq(this).children('img').attr('src',source);
	});
	
	$jq("#c1 li a").mouseout(function(){
		var source = $jq(this).children('img').attr('src');
		source = source.replace(/_hl\.jpg/gi,'.jpg');
		$jq(this).children('img').attr('src',source);
	});
	
	
	$jq('#gallery_link a').click(function(){
		show_loading();
		$jq('#gallery_container').remove();
		var table = $jq(this).attr('name');
		var record_id = $jq(this).attr('id');
		var p = {};
		p['record_id'] = record_id;
		p['table'] = table;
		$jq('body').append('<div id="gallery_container"></div>');
		
		$jq("#gallery_container").load('index.php?/newwater/ajax_slideshow',p,function(str){
			TB_position('gallery_container',600,400);
			load_opacity('gallery_container');
			startGallery();
			hide_loading();
		});
		
		return false;
	});
	
	$jq('ul.inline_left').innerfade({
						speed: 2000,
						timeout: 5000,
						type: 'sequence',
						containerheight: '260px'
					});
	
});

var last_solution = '';
var last_image = '';

