jQuery(document).ready(function() {
   
   
   
   //Change the height of the site
   changeHeight();
    
   // Open Info Div in CenterPanel
   $(".more-info a").click(function(){
        id = ".more-info-divs #" + $(this).attr('href');
        div_vis = $(id).css('display');
        
        if(div_vis == "none"){
            $(".more-info-divs .hidden-noimt").hide();
            $(id).fadeIn("slow");
            $("ul.more-info a").attr("class","");
            $(this).attr("class","cur");
        }else{
            $("ul.more-info a").attr("class","");
            $(id).fadeOut("slow");
        }
        return false;
    });
});




function changeHeight() {
    var pagesize = getPageSize();

    var site_height = $('#site').height();
    var footer_height = $('#footer').height();
    var total_height = site_height + footer_height;


    if(total_height<pagesize[1]) {
        var diff = pagesize[1] - footer_height;
        $('#site').css('height',diff+'px');
    }
}


function getPageSize()
{
	
	var xScroll, yScroll;
	
	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;
	
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	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;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
   





$(document).ready(function() {

	//function addMega(){
	//$(this).addClass("hovering");
	//}
	
	//function removeMega(){
	//$(this).removeClass("hovering");
	//}
	
	
	//function addMega(){
	//$(this).addClass("hovering");
	//$($(this).find("h2 a")).addClass("hover");
	//}
	
	//function removeMega(){
	//$(this).removeClass("hovering");
	//$($(this).find("h2 a")).removeClass("hover");
	//}
	
	
	function addMega(){
	$($(this).find("h2")).addClass("hover");
        $($(this).find("h2 a")).addClass("sel");
	$($(this).find("div.mega-choices")).slideDown("fast");
	$(this).addClass("hovering");
	}
	
	function removeMega(){
	$($(this).find("h2")).removeClass("hover");
	$($(this).find("h2 a")).removeClass("sel");
	$($(this).find("div.mega-choices")).slideUp("fast");
	$(this).removeClass("hovering");
	} 
	
	var megaConfig = {
	interval: 30,
	sensitivity: 4,
	over: addMega,
	timeout: 100,
	out: removeMega
	};
	
	$("li.mega").hoverIntent(megaConfig)

});

function opennewwindow(url,name)
{ 
var height=530;
var width=340;
var display_setting="menubar=0,toolbar=0,screenX=0,screenY=0,top=100,left=100,scrollbars=0,status=0,width="+width+", height="+height; 
window.open(url,name,display_setting); 
}

function opennewswindow(url,name)
{ 
var height=385;
var width=340;
var display_setting="menubar=0,toolbar=0,screenX=0,screenY=0,top=100,left=100,scrollbars=0,status=0,width="+width+", height="+height; 
window.open(url,name,display_setting); 
}

function openlistwindow(url,name)
{ 
var height=screen.availHeight/2;
var width=840;
var display_setting="menubar=0,toolbar=0,screenX=0,screenY=0,top=100,left=100,scrollbars=1,status=0,width="+width+", height="+height; 
window.open(url,name,display_setting); 
}

function opendetailswindow(url,name)
{ 
var height=screen.availHeight;
var width=800;
var display_setting="menubar=0,toolbar=0,screenX=0,screenY=0,top=100,left=100,scrollbars=1,status=0,width="+width+", height="+height; 
window.open(url,name,display_setting); 
}
function opendetailswindow2(url,name)
{ 
var height=screen.availHeight;
var width=950;
var display_setting="menubar=0,toolbar=0,screenX=0,screenY=0,top=100,left=100,scrollbars=1,status=0,width="+width+", height="+height; 
window.open(url,name,display_setting); 
}

function openeditwindow(url,name)
{ 
var height=screen.availHeight;
var width=650;
var display_setting="menubar=0,toolbar=0,screenX=0,screenY=0,top=100,left=100,scrollbars=1,status=0,width="+width+", height="+height; 
window.open(url,name,display_setting); 
}

function changeimage(number,img,description)
{
	$('#image-src').attr('src',img);
	$('#image-description').text(description);
	$('#image-holder-'+number).css('display','none');
	var oldnumber = $('#oldnumber').val();
	$('#image-holder-'+oldnumber).css('display','');
	
	$('#zoom'+oldnumber).css('display','none');
	$('#zoom'+number).css('display','');
	$('#oldnumber').val(number);
}

function showcart(id)
{
	if(id==1) {
		$('#cart-div').css('display','block');
		$('#wishlist-div').css('display','none');
		$('li.inchosen').removeClass('sel');
		$('li.incart').addClass('sel');
		
	} else {
		$('#wishlist-div').css('display','block');	
		$('#cart-div').css('display','none');
		$('li.incart').removeClass('sel');
		$('li.inchosen').addClass('sel');
	}
}


