/*
@ Author: shabingliang
@ E-mail: shabingliang@gmail.com
@ Time:   2010
*/
jQuery(document).ready(function(){
	//Slide up & down
    jQuery('#up').click(function(){
		if(jQuery.browser.safari) {
			jQuery('body').animate({scrollTop:0}, 'slow');
			return false;
		}else{
			jQuery('html').animate({scrollTop:0}, 'slow');
			return false;
		}
	});
	jQuery('#down').click(function(){
		if(jQuery.browser.safari) {
			jQuery('body').animate({scrollTop:jQuery('#footerPan').offset().top}, 'slow');
			return false;
		}else{
			jQuery('html').animate({scrollTop:jQuery('#footerPan').offset().top}, 'slow');
			return false;
		}
	});
	//Menu
	var st = null;
	$("#dropdown > div  a").hover(function(){
		$("div.anylinkcsscols").css({visibility:"hidden",top:"-1000px",left:"-1000px"});
		$this = $(this);
		var offset = $this.offset();
		
		$("#"+$(this).attr("rel")).css({visibility:"visible",top:offset.top+40+"px",left:offset.left+"px"}).hover(function(){
			if(st != null){
				clearTimeout(st);
			}
			st = null;
			$this.addClass("selected");
		},function(){
			$this.removeClass("selected");
			$("div.anylinkcsscols").css({visibility:"hidden",top:"-1000px",left:"-1000px"});
		});
	},function(){
		$target = $("#"+$(this).attr("rel"));
		st = setTimeout(function(){
			$target.css({visibility:"hidden",top:"-1000px",left:"-1000px"});
		},10);
	});
	
	//Fuck firefox
	if(jQuery.browser.mozilla){
		$("#dropdown > .navitem > a").css({"padding":"12px 7px 14px 6px"});
		$("#dropdown > .navitem img").css({"padding-left":"2px"});
	}
	
	//Fuck ie6
	var $currentItem = $("#categories .column");
	$("#categories").css("width",$currentItem.size()*$currentItem.outerWidth(true)+5);
	
	//
	var text = $("#productsListingListingBottomLinks").html();
	$("#productsListingListingTopLinks").append(text);
	
	//
	$("#filterContent").appendTo('.forcfilter').show();
	
	//plus & minus
	$("#plus").click(function(){
		var $this = $("#cart_quantity");
		
		$this.val((parseInt($this.val())+1));
	});
	$("#minus").click(function(){
		var $this = $("#cart_quantity");
		if(parseInt($this.val()) > 1){
			$this.val((parseInt($this.val())-1));
		}
	});
	
	//review & faq
	$('a.iframepopup').click(function(e) {
		e.preventDefault();
        var $this = $(this);
        var horizontalPadding = 30;
        var verticalPadding = 30;
        $('<iframe id="externalSite" class="externalSite" src="' + this.href + '" />').dialog({
        	title: ($this.attr('title')) ? $this.attr('title') : 'laserslinght.com',
            autoOpen: true,
            hide: 'fade',
            show: 'fade',
            width: 800,
            height: 500,
            modal: true,
                
            resizable: true,
            autoResize: true,
                
            overlay : { background: "#000", opacity: 0.1}

       	}).width(800 - horizontalPadding).height(500 - verticalPadding);            
    });
	
	// Selectd default tab
	$("#link20").click(function(){
		selectTab(2,20);						
	}).trigger("click");
	
	// back
	$("#prePage").click(function(){
		history.back(-1);
	});
	
    $("#thumbnail").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
		circular: false,
		visible: 5
    });
	
	// product images
	$("#thumbnail li a").click(function(){
		$("#videosViewCon").hide();
		var newlink = $(this).attr("mpic");
		var newlink1 = $(this).attr("lpic");
		$("#productMainImage > a img").attr('src',newlink);
		$("#productMainImage > a").attr('href',newlink1);
		return false;
	});
	
	$("#videosView").click(function(){
		if($("#videosViewCon").css('display') != 'block'){
			$("#videosViewCon").show();
		}else{
			$("#videosViewCon").hide();			
		}
		return false;
	});

    $('.lefti,.righti,.tooltip').tooltip({ 
		 track: true, 
		 delay: 0, 
		 showURL: false, 
		 showBody: " - ", 
		 fade: 250 ,
		 top: 25,
		 left:-150
	});
	//remove 
	$("#clearrecent").click(function(){
		$.cookie('pviewlist',null);
		$("#recentlyview").remove();
		return false;
	});
});

var copytoclip=1;

function HighlightAll(theField) {
	var tempval=eval("document."+theField);
	tempval.focus();
	tempval.select();
	if (document.all&&copytoclip==1){
		therange=tempval.createTextRange();
		therange.execCommand("Copy");
		window.status="Contents highlighted and copied to clipboard!";
		setTimeout("window.status=''",1800);
	}
}

function clearAllTabs(menu) {
	if (menu==2){
		$('#tab11').hide();
		$('#link11').removeClass().addClass('normal');
		
		$('#tab12').hide();
		$('#link12').removeClass().addClass('normal');
		
		$('#tab20').hide();
		$('#link20').removeClass().addClass('normal');
		
		$('#tab30').hide();
		$('#link30').removeClass().addClass('normal');
		
		$('#tab40').hide();
		$('#link40').removeClass().addClass('normal');
	}
	if (menu==1){
		$('#tab1').hide();
		$('#link1').removeClass().addClass('normal');
		
		$('#tab2').hide();
		$('#link2').removeClass().addClass('normal');
		
		$('#tab40').hide();
		$('#link40').removeClass().addClass('normal');
	}
}
// tab function
function selectTab(menu, id) {
	clearAllTabs(menu);
	$("#link"+id).removeClass().addClass('current');
 	$('#tab'+id).show();
}
