//When the DOM tree is loaded
$(document).ready(function() {
    //Add pointer class to .photo .item
    $(".photo .item").addClass("pointer");

    //Hover over photo fade in hidden span
    $(".photo .item").hover(
        function() {
            $(this).find("span").fadeIn();
        },
        function() {
            $(this).find("span").fadeOut();
        }
    );

  $('.search_box').keypress(function(event) {
    var key = event.keyCode ? event.keyCode : event.which;
    if (key == 13) {
      var href = "/Search?search=" + $('.search_box').val();
      window.location = href;
      return false;
    }
  });

  $('#xsltsearch .submit').click(function() {
    var search = $('#xsltsearch .input').val();
    var href = "/Search?search=" + search;
    window.location = href;
    return false;
  });
  $('#xsltsearch .input').keypress(function(event) {
    var search = $('#xsltsearch .input').val();
    var key = event.keyCode ? event.keyCode : event.which;
    if (key == 13) {
      var href = "/Search?search=" + search;
      window.location = href;
      return false;
    }
  });
});




$(document).ready(function() {
  var href;

    $(".flashmenu").media({ width: 900, height: 42, autoplay: true, caption: false, bgColor: 'transparent',  params: { quality: 'high', menu: 'false' } });
    $(".flashheader").media({ width: 915, height: 200, autoplay: true, caption: false, bgColor: 'transparent',  params: { quality: 'high', menu: 'false' } });

  $("dt.menu_1:not(.selected)").hover(
      function () {
        $(this).css({'background-color' : '#BBE4FE', 'font-weight' : 'normal'});
      }, 
      function () {
        $(this).css({'background-color' : 'white', 'font-weight' : 'normal'});
      }
  );
  $("dt.menu_2:not(.selected) ").hover(
      function () {
        $(this).css({'background-color' : '#BBE4FE', 'font-weight' : 'normal'});
      }, 
      function () {
        $(this).css({'background-color' : 'white', 'font-weight' : 'normal'});
      }
  );
  $(".slideMenu li:not(.selected) ").hover(
      function () {
        $(this).css({'background-color' : '#BBE4FE', 'font-weight' : 'normal'});
      }, 
      function () {
        $(this).css({'background-color' : 'white', 'font-weight' : 'normal'});
      }
  );

  $("dd.menu_1:not(:first)").hide();
  $("dt.menu_1 a").click(function(){
    href = $(this).attr('href');
    //$("dd.menu_1:visible").hide();//slideUp("slow");
    //$("dd.menu_1:visible").addClass(".moveUp");
    //$(this).parent().next().show();//slideDown("slow");
    //$(this).parent().next().addClass(".moveDown");
    var wait = setInterval(function() {
      if( !$(".moveUp, .moveDown").is(":animated") ) {
        clearInterval(wait);
        window.location = href;
      }
   }, 500);
   return false;
  });
  $("dd.menu_2:not(:first)").hide();
  $("dt.menu_2 a").click(function(){
    href = $(this).attr('href');
    //$("dd.menu_2:visible").hide();//slideUp("slow");
    //$("dd.menu_2:visible").addClass("moveUp");
    //$(this).parent().next().show();//slideDown("slow");
    //$(this).parent().next().addClass("moveDown");
    var wait2 = setInterval(function() {
      if( !$(".moveUp, .moveDown").is(":animated") ) {
        clearInterval(wait2);
        window.location = href;
      }
    }, 500);
    return false;
  });
  $("dd").hide();
  $("dd .selected").parent().parent().show();
  $("dd.selected").show();
  $("dd.menu_2 .selected").parent().parent().parent().parent().show();

  $("a.lightbox").lightBox();

  $(".inherit_height").each(function(i) {
    //thisHeight = $(this).innerHeight(true);
    //alert(thisHeight );
    thisHeight = $("#container").outerHeight(true);
    alert(thisHeight );
    $(this).height(thisHeight - 92);
  });

  //$("img.reflect").reflect({height: 0.3, opacity: 0.5});
  
//SETTING UP OUR POPUP   
//0 means disabled; 1 means enabled;   
var popupStatus = 0; 
//loading popup with jQuery magic!   
function loadPopup(){   
  //loads popup only if it is disabled   
  if(popupStatus==0){   
    $("#backgroundPopup").css({   
      "opacity": "0.7"  
    });   
    $("#backgroundPopup").fadeIn("slow");   
    $("#foregroundPopup").fadeIn("slow");   
    popupStatus = 1;   
  }   
}  
//disabling popup with jQuery magic!   
function disablePopup(){   
  //disables popup only if it is enabled   
  if(popupStatus==1){  
    href =$(".productlink").attr('href');
    window.location = href;
    $("#backgroundPopup").fadeOut("slow");   
    $("#foregroundPopup").fadeOut("slow");   
    popupStatus = 0;   
  }   
}  
//centering popup   
function centerPopup(){   
  //request data for centering   
  var windowWidth = document.documentElement.clientWidth;   
  var windowHeight = document.documentElement.clientHeight;   
  var popupHeight = $("#foregroundPopup").height();   
  var popupWidth = $("#foregroundPopup").width();    
  //centering   
  $("#foregroundPopup").css({   
    "position": "fixed",   
    "top": windowHeight/2-popupHeight/2,   
    "left": windowWidth/2-popupWidth/2   
  });   
  //only need force for IE6   
  $("#backgroundPopup").css({   
    "height": windowHeight   
  });   
}  

  if ($.getQueryString({ ID:"addcart" }) != "undefined") {
    //centering with css   
    centerPopup();   
    //load popup   
    loadPopup();  
  }

  //LOADING POPUP   
  //CLOSING POPUP   
  //Click the x event!   
  $("#popupContactClose").click(function(){   
    disablePopup();   
  });  
  
  //Click out event!   
  $("#backgroundPopup").click(function(){   
    disablePopup();   
  });   

  //Press Escape event!   
  $(document).keypress(function(e){   
    if(e.keyCode==27 && popupStatus==1){   
      disablePopup();   
    }   
  }); 

//SETTING UP OUR POPUP REP  
//0 means disabled; 1 means enabled;   
var popupStatusRep = 0; 
//loading popup with jQuery magic!   
function loadPopupRep(){   
  //loads popup only if it is disabled   
  if(popupStatusRep==0){   
    $("#backgroundPopupRep").css({   
      "opacity": "0.7"  
    });   
    $("#backgroundPopupRep").fadeIn("slow");   
    $("#foregroundPopupRep").fadeIn("slow");   
    popupStatusRep = 1;   
  }   
}  
//disabling popup with jQuery magic!   
function disablePopupRep(){   
  //disables popup only if it is enabled   
  if(popupStatusRep==1){  
    $("#backgroundPopupRep").fadeOut("slow");   
    $("#foregroundPopupRep").fadeOut("slow");   
    popupStatusRep = 0;   
  }   
}  
//centering popup   
function centerPopupRep(){   
  //request data for centering   
  var windowWidth = document.documentElement.clientWidth;   
  var windowHeight = document.documentElement.clientHeight;   
  var popupHeight = $("#foregroundPopupRep").height();   
  var popupWidth = $("#foregroundPopupRep").width();    
  //centering   
  $("#foregroundPopupRep").css({   
    "position": "fixed",   
    "top": windowHeight/2-popupHeight/2,   
    "left": windowWidth/2-popupWidth/2   
  });   
  //only need force for IE6   
  $("#backgroundPopupRep").css({   
    "height": windowHeight   
  });   
}  

  $(".to_be_pop").click(function(){
    //centering with css   
    centerPopupRep();   
    //load popup   
    //alert($(this).parent().parent().children(".popup").text());
    $("#foregroundPopupRep").empty();
    $("#foregroundPopupRep").append("<a id='popupContactCloseRep'>x</a>");
    $("#foregroundPopupRep").append($(this).parent().parent().children(".popup").contents());
    $("#popupContactCloseRep").click(function(){   
      disablePopupRep();   
    }); 
    loadPopupRep();
    return false;  
  });

  //LOADING POPUP   
  //CLOSING POPUP   
  //Click the x event!   
  $("#popupContactCloseRep").click(function(){   
    disablePopupRep();   
  });  
  
  //Click out event!   
  $("#backgroundPopupRep").click(function(){   
    disablePopupRep();   
  });   

  //Press Escape event!   
  $(document).keypress(function(e){   
    if(e.keyCode==27 && popupStatusRep==1){   
      disablePopupRep();   
    }   
  }); 



//SETTING UP OUR POPUP MAP
//0 means disabled; 1 means enabled;   
var popupStatusMap = 0; 
//loading popup with jQuery magic!   
function loadPopupMap(){   
  //loads popup only if it is disabled   
  if(popupStatusMap==0){   
    $("#backgroundMapPopup").css({   
      "opacity": "0.7"  
    });   
    $("#backgroundMapPopup").fadeIn("slow");   
    $("#foregroundMapPopup").fadeIn("slow");   
    popupStatusMap = 1;   
	$('div[class=map]').each(function() {
		
		$(this).addClass('mapdimensions');
		var mapId = $(this).attr('id');
		
		var value = $(this).html();
		value = $.trim(value);
		
		var point = value.split(',');

		var lat = parseFloat(point[0]);
		var lon = parseFloat(point[1]);
		var zoom = parseFloat(point[2]);
		
		var fm = {};
		fm.maps = new Array();
		fm.maps[fm.maps.length] = new GMap2(document.getElementById(mapId));
		var m = fm.maps[fm.maps.length-1];
		
		var p = new GLatLng(lat, lon);
		m.setCenter(p, zoom); 
			
		m.addControl(new GSmallMapControl());
		m.addControl(new GMapTypeControl()); 

		var marker = new GMarker(p);
		m.addOverlay(marker);	
	});
  }   
}
//disabling popup with jQuery magic!   
function disablePopupMap(){   
  //disables popup only if it is enabled   
  if(popupStatusMap==1){  
    $("#backgroundMapPopup").fadeOut("slow");   
    $("#foregroundMapPopup").fadeOut("slow");   
    popupStatusMap = 0;   
  }   
}  
//centering popup   
function centerPopupMap(){   
  //request data for centering   
  var windowWidth = document.documentElement.clientWidth;   
  var windowHeight = document.documentElement.clientHeight;   
  var popupHeight = $("#foregroundMapPopup").height();   
  var popupWidth = $("#foregroundMapPopup").width();    
  //centering   
  $("#foregroundMapPopup").css({   
    "position": "fixed",   
    "top": windowHeight/2-popupHeight/2,   
    "left": windowWidth/2-popupWidth/2   
  });   
  //only need force for IE6   
  $("#backgroundMapPopup").css({   
    "height": windowHeight   
  });   
}  

  $("a.mapWA").click(function(){
    //centering with css   
    centerPopupMap();   
    //load popup   
    loadPopupMap();  
    $("#mapWA").show();
    $("#mapQLD").hide();
  });
  $("a.mapQLD").click(function(){
    //centering with css   
    centerPopupMap();   
    //load popup   
    loadPopupMap();  
    $("#mapWA").hide();
    $("#mapQLD").show();
  });

  //LOADING POPUP   
  //CLOSING POPUP   
  //Click the x event!   
  $("#popupMapClose").click(function(){   
    disablePopupMap();   
  });  
  
  //Click out event!   
  $("#backgroundMapPopup").click(function(){   
    disablePopupMap();   
  });   

  //Press Escape event!   
  $(document).keypress(function(e){   
    if(e.keyCode==27 && popupStatusMap==1){   
      disablePopupMap();   
    }   
  }); 

});