var _as = [];
var _time;
var _obj;
var _initPageRun = true;

function beginRequestAsync() {
  _initPageRun = false;
}

function initPageAsync() {
  if (!_initPageRun) {
      _initPageRun = true;
  	  $("div.img-holder").each(function(i){
		  $(this).attr({'id':'aaa-'+i});
		  $(this).hover(
			  function (){
				  _time = setTimeout("showP('" + $(this).attr('id') + "')", 200);
			  },
			  function (){
				  clearTimeout(_time);
				  setTimeout("hideP('" + $(this).attr('id') + "')", 1);
			  }
		  );
	  });
  	
	  $(".item-list .options li a.down").click(function(){
		  showPopup($(this).attr("href"));
		  return false;
	  });
  	
	  $(".bottomlink a").click(function(){
		  showPopup($(this).attr("href"));
		  return false;
	  });
  	
	  $(".open-poup-up-links a").click(function(){
		  //showPopup($(".dressesName").val());
		  if($(this).attr("href").indexOf("javascript") == -1)
		  {
		    showPopup($(this).attr("href"));
		    return false;
		  }
	  });

	  $(".fader .close").click(hidePopup);
	}
}

function initPage() {

	  $("a.close-filters").click(function (){
		  if($(this).hasClass("close")) {
			  $(this).removeClass("close").text("Close filters");
			  $("div.filters-box").slideDown(300);
		  }else {
			  $(this).addClass("close").text("Filters");		
			  $("div.filters-box").slideUp(300);
		  }
		  return false;
	  });
	  $("a.minimize").click(function (){
		  if($(this).hasClass("close")) {
			  $(this).removeClass("close").text("Minimize view");
			  $("div.bottom-box .content").slideDown(300);
		  }else {
			  $(this).addClass("close").text("Maximize view");		
			  $("div.bottom-box .content").slideUp(300);
		  }
		  return false;
	  });
	  $("div.img-holder").each(function(i){
		  $(this).attr({'id':'aaa-'+i});
		  $(this).hover(
			  function (){
				  _time = setTimeout("showP('" + $(this).attr('id') + "')", 200);
			  },
			  function (){
				  clearTimeout(_time);
				  setTimeout("hideP('" + $(this).attr('id') + "')", 1);
			  }
		  );
	  });
  	
	  $(".item-list .options li a.down").click(function(){
		  showPopup($(this).attr("href"));
		  return false;
	  });
  	
	  $(".bottomlink a").click(function(){
		  showPopup($(this).attr("href"));
		  return false;
	  });
  	
	  $(".open-poup-up-links a").click(function(){
		  //showPopup($(".dressesName").val());
		  if($(this).attr("href").indexOf("javascript") == -1)
		  {
		    showPopup($(this).attr("href"));
		    return false;
		  }
	  });

	  
}

function showP(poupUpid) {
	$('#'+poupUpid).parent().css({"position":"relative", "z-index":"100"});
	if ($.browser.msie) $('#'+poupUpid).children('div.popup').css({"display":"block"});
    else $('#'+poupUpid).children('div.popup').fadeIn(400);
}
function hideP(poupUpid) {
	if ($.browser.msie) $('#'+poupUpid).children('div.popup').css({"display":"none"});
	else $('#'+poupUpid).children('div.popup').fadeOut(400);
	$('#'+poupUpid).parent().css({"z-index":"0"});
}

function ajaxedPopup (_popup){
	$.ajax({
		type: "GET",
		//url: "/popup/"+_popup+".html",
		url: _popup,
		dataType: "html",
		success: function(_html){
			$(".load-status").hide("fast");
	    	$("#lightbox").html(_html);
			$(".lightbox").fadeIn(1000);
			poupUp_height();
			$("#cancel").click(hidePopup);
			$(".fader .close").click(hidePopup);
	    }
	});
}
/* show popup */
function showPopup(_poupUp){
		$(".fader").fadeIn(200);
		$(".load-status").show("fast");
		ajaxedPopup(_poupUp);
		if ($.browser.msie){
			var _poupUp = document.getElementById("fader");
			if (_poupUp)hideSelectBoxes(_poupUp);
		}		
		poupUp_height();
	}
/* hide popup */
function hidePopup(){
	$(".lightbox").fadeOut(200);
	$(".fader").fadeOut(500);
	if ($.browser.msie){
		var _poupUp = document.getElementById("fader");
		if (_poupUp)showSelectBoxes(_poupUp);
	}
}



if (window.addEventListener)
	window.addEventListener("load", initPage, false);
else if (window.attachEvent)
	window.attachEvent("onload", initPage);

