jQuery(document).ready(function($){

	$("#nav li").hover(
		function(){$(this).addClass("sfHover");}, 
		function(){$(this).removeClass("sfHover");}
	);

	pngFixer("div");
	$("div.balance").columnize();
	$("div.balance-features").columnize({columns:3});
	
	/* product slider */
	var productWindowSize = 2; // number of products visible at one time
	var animationDuration = 400; // ms
	
	var totalProducts = $(".featured-product").length;
	var productWidth = 330; //$('.featured-product').css("width");
	// productWidth = productWidth.substring(0, productWidth.lastIndexOf("px"));
	
	//$('.featured-products').css("width",(productWindowSize*productWidth)+"px");
	//$('.products-wrapper').css("width",(totalProducts*productWidth)+"px");
	$('.featured-left-arrow').click(function () {
		var position = $(".products-wrapper").position();
		if (position.left < 0) {
			$('.products-wrapper').stop().animate({"left":"+="+productWidth+"px"}, animationDuration);
		} else {
			$('.products-wrapper').stop().animate({"left":"-" + ((totalProducts-productWindowSize)*productWidth) + "px"}, animationDuration);
		}
	});
	$('.featured-right-arrow').click(function () {
		var position = $(".products-wrapper").position();
		if (position.left > -((totalProducts-productWindowSize)*productWidth)) {
			$('.products-wrapper').stop().animate({"left":"-="+productWidth+"px"}, animationDuration);
		} else {
			$('.products-wrapper').stop().animate({"left":"0px"}, animationDuration);
		}
	});
	
	var winHeight = $(window).height();
	var docHeight = $(document).height();
	if (docHeight < winHeight) {
		$(".mesh").height(winHeight);
	} else {
		$(".mesh").height(docHeight);
	}
	
	$("#gallery .images").jScrollPane({scrollbarWidth:11, scrollbarMargin:0, reinitialiseOnImageLoad:true});
});
function pngFixer(ele) {
	var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
	var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);
	$(ele).each(function() {
		if (ie55 || ie6) {
			// fix css background pngs
			var bgIMG = jQuery(this).css('background-image');
			if (bgIMG.indexOf(".png") != -1) {
				var iebg = bgIMG.split('url("')[1].split('")')[0];
				jQuery(this).css('background-image', 'none');
				jQuery(this).get(0).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + iebg + "',sizingMethod='crop')";
			}
		}
	});
}
function showPopup(url, name, height, width, scroll, resizable, statusbar, screenpos) {
	var Xwin = width;
	var Ywin = height;
	var Xsize = screen.availWidth;
	var Ysize = screen.availHeight;
	var Xpos = 0;
	var Ypos = 0;
	switch(screenpos) {
		case "topleft":
			Xpos = 0;
			Ypos = 0;
			break;
		case "topright":
			Xpos = Xsize - width;
			Ypos = 0;
			break;
		case "bottomleft":
			Xpos = 0;
			Ypos = Ysize - height;
			break;
		case "bottomright":
			Xpos = Xsize - width;
			Ypos = Ysize - height;
			break;
		default:
			Xpos = (Xsize - width) / 2;
			Ypos = (Ysize - height) / 2;
			break;
	}
	var popwin;
	var opts = "status=" + statusbar + ",resizable=" + resizable + ",scrollbars=" + scroll + ",height=" + Ywin + ",width=" + Xwin + ",left=" + Xpos + ",top=" + Ypos;

	popwin = window.open(url, name, opts);
	if (popwin != null) {
		popwin.blur();
	} else {
		if (confirm("We cannot open a popup window automatically, click on OK to open the webpage in a normal window, otherwise click CANCEL to stay on this page.\n\nNote: user experience may change as a result of viewing popup webpages in normal windows.")) {
			location.href = url;
		}
	}
}
function showPlayer() {
	showPopup("/wp-content/themes/thebox/player.html", "aerial", 90, 324, 0, 0, 0);
}
/*
//specify page to pop-under
var popunder = "/wp-content/themes/thebox/player.html"

//specify popunder window features
//set 1 to enable a particular feature, 0 to disable
var winfeatures = "width=324,height=90"

//Pop-under only once per browser session? (0=no, 1=yes)
//Specifying 0 will cause popunder to load every time page is loaded
var once_per_session = 1

///No editing beyond here required/////

function get_cookie(Name) {
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) { // if cookie exists
      offset += search.length
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1)
         end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
      }
   }
  return returnvalue;
}

function loadornot(){
	if (get_cookie('popunder')==''){
		loadpopunder();
		document.cookie = "popunder=yes";
	}
}

function loadpopunder(){
	win2 = window.open(popunder,"",winfeatures);
	win2.blur();
	window.focus();
}

if (once_per_session==0) {
	loadpopunder()
} else {
	loadornot()
}
*/
