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).Puff(500,function(){
					$jq("#"+affected).remove();
				});
				last_vessel = '';
				//$jq("body").css('overflow','auto');
			})
		
		$jq("a.clear_opacity").click(function(){
				$jq("#opacity").hide();
				$jq("#"+affected).Puff(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','300','100');
		 
		 $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 add_client_overlay(overlay)
 {
	 var page_size = getPageSize();
	 var height = page_size[1] *.5;
	 var width = page_size[0] * .5;
	 $jq("#"+overlay).width(width+"px");
	 $jq("#"+overlay+" .scrollable").height(height-50+"px");
	 
	 TB_position(overlay,width,height);
	 
	 $jq("#"+overlay).Grow(500);
	 load_opacity(overlay);
	 hide_loading();		
 }
  
 function clear_client_overlay()
 {
	  hide_loading();
	  $jq("#overlay").remove();
	  $jq("#opacity").fadeOut('fast');
 }
 
 function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '' + num + '.' + cents);
}





$jq(document).ready(function(){

	$jq("#r6 ul li a").mouseover(function(){
		var original_src = $jq(this).children('img').attr('src');
		var osplit = original_src.split('_');
		$jq(this).children('img').attr('src','/d_images/home_'+osplit[2]+'_on.jpg');
	});
	
	$jq("#r6 ul li a").mouseout(function(){
		var original_src = $jq(this).children('img').attr('src');
		var osplit = original_src.split('_');
		$jq(this).children('img').attr('src','/d_images/home_'+osplit[2]+'_off.jpg');
	});
	
	$jq(".small_thumb img").wrap("<div class='wrap1'><div class='wrap2'>" + "<div class='wrap3'></div></div></div>");
	$jq("img.dropshadow").wrap("<div class='wrap1'><div class='wrap2'>" + "<div class='wrap3'></div></div></div>");
	$jq("#productMainImage img").wrap("<div class='wrap1'><div class='wrap2'>" + "<div class='wrap3'></div></div></div>");
	$jq("#productAdditionalImages img").wrap("<div class='wrap1'><div class='wrap2'>" + "<div class='wrap3'></div></div></div>");
	$jq(".centerBoxWrapper img").wrap("<div class='wrap1'><div class='wrap2'>" + "<div class='wrap3'></div></div></div>");
	$jq(".productListing-odd img").wrap("<div class='wrap1'><div class='wrap2'>" + "<div class='wrap3'></div></div></div>");
	$jq(".productListing-even	 img").wrap("<div class='wrap1'><div class='wrap2'>" + "<div class='wrap3'></div></div></div>");
	
	$jq(".b_list .copy .list").each(function(i){
								//			alert($jq(this).attr('class'));
		if(i%2 == 0)
		{
			$jq(this).before('<div class="bg_even_top"></div>').after('<div class="bg_even_bottom"></div>');
			$jq(this).addClass('bg_list_even');	
			if(is.ie)$jq(this).children('.thumb').css('display','none');
		}
	});
	
	
	$jq(".files img.dropshadow").click(function(){
		id =  $jq(this).attr('id');
		
		
		show_loading();
		jQuery.get('/index.php?/jconcepts/get_full_image/'+id,'',function(str){
		 $jq("body").append('<div class="overlay" id="overlay_'+id+'"></div>');
		 var str_split = str.split('SPLIT');
		 var size = str_split[0].split('DIMENSION');
		 var height = parseInt(size[0]) + ((parseInt(size[2])/parseInt(size[1]))*100);
		 var width = parseInt(size[1])+40;
		$jq("#overlay_"+id).html(str_split[1]);
		hide_loading();
		
		TB_position('overlay_'+id,height, width);
		$jq("#overlay_"+id).fadeIn();
		load_opacity("overlay_"+id)
		$jq(".overlay").click(function(){
			
			$jq("#opacity").hide();
				$jq("#overlay_"+id).Puff(500,function(){
					$jq("#overlay_"+id).remove();
					return false;
				});
			
			});
		
		});
		return false;
		last_image = id;	
	});
	
	
	$jq(".pic img").click(function(){
		id =  'about';
		
		var source = $(this).attr('src');
		source = source.replace(/thumb/gi,'full');
		
		var p = {};
		p['source'] = source;
		p['caption'] = $(this).siblings('div').html();
		
		show_loading();
		jQuery.post('/index.php?/jconcepts/get_about_image/',p,function(str){
		 $jq("body").append('<div class="overlay" id="overlay_'+id+'"></div>');
		 var str_split = str.split('SPLIT');
		 var size = str_split[0].split('DIMENSION');
		 var height = parseInt(size[0]) + ((parseInt(size[2])/parseInt(size[1]))*100);
		 var width = parseInt(size[1])+40;
		$jq("#overlay_"+id).html(str_split[1]);
		hide_loading();
		
		TB_position('overlay_'+id,height, width);
		$jq("#overlay_"+id).fadeIn();
		load_opacity("overlay_"+id)
		$jq(".overlay").click(function(){
			
			$jq("#opacity").hide();
				$jq("#overlay_"+id).Puff(500,function(){
					$jq("#overlay_"+id).remove();
				});
			
			});
		
		});
		return false;
	});
	
	
	//faq stuff
 	$jq("#b_faq li.q").click(function(){
		var next = $jq(this).next();
		if(next.attr('class')=='a_on') next.removeClass('a_on').addClass('a').slideUp('fast');
		else next.removeClass('a').addClass('a_on').slideDown('fast');
	});
	
	//cart rollovers
	$jq(".cat_level_1 .category_text a").mouseover(function(){
		var img_loc = $jq(this).children('img').attr('src');		
		var parent_on = $jq(this).parent('div').parent('div').attr('class');
		if(parent_on.match(/_on/gi)  <=0) 
		{
			var new_loc = img_loc.replace(/\.gif/gi,'_on.gif');
			$jq(this).children('img').attr('src',new_loc);
		}
	});
	
		$jq(".cat_level_1 .category_text a").mouseout(function(){
		var img_loc = $jq(this).children('img').attr('src');		
		var parent_on = $jq(this).parent('div').parent('div').attr('class');
	
			if(parent_on.match(/_on/gi)  <=0) 
		{
			var new_loc = img_loc.replace(/_on/gi,'');
			$jq(this).children('img').attr('src',new_loc);
		}
	});
	
	create_slideshow();
	
});

var last_solution = '';
var last_image = '';

var loaded = 1;

function create_slideshow()
{
	for(i=1;i<=16;i++)
	{
			$("#r3").append('<li><img src="/d_images/banner_'+i+'.jpg" id="img_'+i+'" /></li>');
	}
	
	$("#img_9").load(function(){
			$('#r3').innerfade({ animationtype: 'fade', speed: 900, timeout: 5000, type: 'random', containerheight: '160px' });
	});
	
}

