(function($){

	/* 
		script for "featured boxes" 
		
		transform img el into div with background image in order to apply border-radius css property 
		(border-radius does not work on img el)
	*/
	$(".box-featured").each(function() {
		
		var cache = {};
		
		cache.$this = $(this);
		cache.div = $("<div />");
		cache.img = cache.$this.find("img");
		cache.src = cache.img.attr("src");
		cache.height = cache.img.height;
		
		cache.div.css({
			"background-image": "url(" + cache.src + ")"
		});
		cache.div.addClass("box-image");
		
		cache.$this.append(cache.div);
		cache.img.remove();
		
		cache = {};
		
	
	});
	
	$(".ie8 .box-featured").first().css("margin-left", "0");
	
	
	/*
		add class to every single "article" (item) in a list
		in order to remove border under article
	
	*/
	$("#content .article").last().addClass("last");

	
	/*
		enable colored numbers in an ordered list
	*/
	$("#content ol li").wrapInner("<span>");
	
	
	/*
		simulation of nth-child selector for IE
	*/
	$(".ie7 .box:nth-child(odd), .ie8 .box:nth-child(odd)").addClass("odd");
	$(".ie7 .box:nth-child(even), .ie8 .box:nth-child(even)").addClass("even");
	
	
	/*
		last item in cart without border
	*/	
	$("#content .cart tr.item").last().addClass("last");
	$("#sidebar .cart tr.item").last().addClass("last");
	
	
	/*
		main menu submenu
	*/
	
	$("#main-nav .submenu").hide();
	
	$("#main-nav > ul > li").hover(function() {
	
		
		var $this = $(this);
		var $a = $this.find("a").first();;
		
		
		$a.addClass("active-hover");
		$this.find(".submenu").show();
		

	}, function() {
		

		
		var $this = $(this);
		var $a = $this.find("a").first();;
		
		
		$a.removeClass("active-hover");
		$this.find(".submenu").hide();	
	
	});
	
	
	$(".box-featured").each(function() {
		
		var $this = $(this);
		
		$this.css("cursor", "pointer");
		
		$this.click(function() {
		
			window.location = $this.find("a").first().attr("href");
			
			return false;
		
		});
	
	});
	
	$("#home .box:nth-child(4n+1)").addClass("first");
	$("#sidebar .box:last-child").addClass("last");
	
})(jQuery);

$(document).ready(function(){

	ReSizeBanner();

	$(window).scroll(function() {
		ReSizeBanner();
	});
});


function ReSizeBanner(mod)
{
	if(is_sckyscraper)
	{
		var pageBottom = 997;
		var page = getPageSize();
		var scroll = getPageScroll();
		// alert(page[1] - scroll[1]);
		$('#testjs').html(page[1] - scroll[1]);
		if((page[1] - scroll[1]) < pageBottom)
		{
			var acwidth = 119 - (pageBottom- (page[1] - scroll[1]));
			$('.banner-skyscraper').css
			(
				"top", acwidth + "px"
			);
		}
		else
		{
			
			$('.banner-skyscraper').css
			(
				"top","119px"
			);
		}
	}
}

function GetInputFormIn(input, label)
{
	if(input.value == label)
	{
		input.value = '';
	}
}

function GetInputFormOut(input, label)
{
	if(input.value == '')
	{
		input.value = label;
	}
}

function getPageScroll()
{

	var yScroll;

	if (self.pageYOffset)
	{
		yScroll = self.pageYOffset;
	} 
	else if (document.documentElement && document.documentElement.scrollTop)
	{
		yScroll = document.documentElement.scrollTop;
	}
	else if (document.body)
	{
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}


function getPageSize()
{
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY)
	{	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	}
	else if (document.body.scrollHeight > document.body.offsetHeight)
	{
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	}
	else
	{ 
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight)
	{	
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} 
	else if (document.documentElement && document.documentElement.clientHeight)
	{
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{ 
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	

	if(yScroll < windowHeight)
	{
		pageHeight = windowHeight;
	}
	else
	{ 
		pageHeight = yScroll;
	}
	if(xScroll < windowWidth)
	{	
		pageWidth = windowWidth;
	}
	else
	{
		pageWidth = xScroll;
	}
	if(navigator.product == 'Gecko')
	{
		pageHeight = pageHeight - 50;
	}
	
	
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
