
  /* Modified by Alex Spooner, 2009-05-20 11:00:50 EST */

	//$(document).ready(function(){ if (document.location.hash=='#Start-straps') startFlashVid(); });

	function startFlashVid() {
		$("#videopanel").show();
		flashembed("loading", { src: "/flashes/loading.swf", wmode: 'transparent'});
		flashembed("video", { src: "/flashes/video_normal.swf", wmode: 'transparent'});
	}
	function stopFlashVid() {
		$("#videopanel").hide();
	}

	function startFlashVid2() {
		$("#videopanel2").show();
		flashembed("loading2", { src: "/flashes/loading_wide.swf", wmode: 'transparent'});
		flashembed("video2", { src: "/flashes/video_smalto.swf", wmode: 'transparent'});

	}
	function stopFlashVid2() {
		$("#videopanel2").hide();
	}

  var params = {
    menu: "false",
    wmode: "transparent",
    bgcolor: "000000"
  };

  function setCookie(name,value,days)
  {
    if (days)
    {
      var date = new Date();
      date.setTime(date.getTime()+(days*24*60*60*1000));
      var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
  }

  function getCookie(name)
  {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++)
    {
      var c = ca[i];
      while (c.charAt(0)==' ') c = c.substring(1,c.length);
      if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
  }

  function loadMain(p)
  {
    $("#flash_splash").remove();
    document.location = "#" + p;
    loadPage(p);
  }

  function removesplash()
  {
    $("#flash_splash").remove();
  }
  
  function loadPage(p,code)
  {
    var flashvars = null;
    $("#content_900").fadeOut("slow");
	if(p=="Start-straps") { startFlashVid(); }
	else if (p!=null && p>"") {
      // GO TO SHOP
      if (p.search("shop_")!=-1) {
        if (p=="shop_straps") document.location = "http://shop.glamrockwatches.com/straps/";
        else if (p=="shop_case-covers") document.location = "http://shop.glamrockwatches.com/case-covers/";
        else if (p=="shop_time-pieces") document.location = "http://shop.glamrockwatches.com/time-pieces/";
        else if (p=="shop_monogram-leather-goods") document.location = "http://shop.glamrockwatches.com/monogram-leather-goods/";
        else document.location = "http://shop.glamrockwatches.com/time-pieces/" + p.replace(/shop_/, "") + "/";
        return;
      }
      if (!$.browser.msie && document.location.hash.substring(1)!=p) {
        document.location = "#" + p;
        return;
      }
      if (document.location.hash>"") if (document.location.hash.substring(1)!=p) $.history.load(p); // history
      
      if (p=="discover") {
        var flashvars = {
          url1: "javascript:loadPage('shop_time-pieces');",
          url2: "javascript:loadPage('shop_time-pieces');",
          url3: "javascript:loadPage('shop_time-pieces');",
          url4: "javascript:loadPage('shop_time-pieces');",
          url5: "javascript:loadPage('shop_time-pieces');",
          url6: "javascript:loadPage('shop_time-pieces');"
        };
      } else {
        var flashvars = {
          page: p,
          xml: "/xml/"+p
        };
      }
      //onloadFlash(p);
      $("#flash_catalog").fadeOut("slow", function () {
        $.swfobject.embedSWF("/flashes/GlamRockIndex.swf", "flash_catalog", "100%", "100%", "10.1.0", "/flashes/expressInstall.swf", flashvars, params);
        if (typeof p != "undefined") {
          if (p.substr(0,5)=="shop_" && getCookie("usonly")==null) {
            setCookie("usonly","true");
            boxIt2("/us-delivery-only.html","ATTENTION");
          }
        }
      });
    }
  }
  
  function onloadFlash(p) {
    var movie = window.document.flash_music;
    var loaded = false;
    if (typeof movie.PercentLoaded != "undefined") {
      if (movie.PercentLoaded()==100) loaded = true;
    }
    if (loaded) {
      if (p.search("shop_")!=-1) {
       movie.GotoFrame(3);       
      } else {
       movie.GotoFrame(4);       
      }
    } else {
      setTimeout("onloadFlash('"+p+"')",500);
    }
  }
  
  function addToCart(code)
  {
    $.get("/addtocart.php?code="+code,function(data){
      viewCart();
    });
  }
  
  function removeFromCart(code)
  {
    $.get("/removefromcart.php?code="+code,function(data){
      viewCart();
    });
  }
  
  function updateCart(code,qty)
  {
    $.get("/updatecart.php?code="+code+"&qty="+qty,function(data){
      viewCart();
    });
  }
  
  function viewCart()
  {
    $("#content_900").load("/cart.php",function(){

      $("#content_900").fadeIn("slow");
      
      $(".col_name a").click(function(event){
        event.preventDefault();
        $(this).blur();
      });

      $(".col_name").hover(
        function(){
          $("#thumb"+$(this).attr("id")).fadeIn("slow");
        },
        function(){
          $("#thumb"+$(this).attr("id")).fadeOut("slow");
        }
      );

      $("#cart_table a.remove").click(function(event){
        event.preventDefault();
        removeFromCart($(this).attr("title"));
      });

      $("#cart_table select").change(function(event){
        updateCart($(this).attr("name"),$(this).attr("value"));
      });

      $("#continue").click(function(event){
        event.preventDefault();
        $("#content_900").fadeOut("slow");
      });
    
    });
  }
  
  var $ = jQuery.noConflict();
  $(document).ready(function(){
	//if (document.location.hash=='#Start-straps') startFlashVid();
    $.swfobject.embedSWF("/flashes/GlamRockMusic.swf", "flash_music", "990", "30", "10.1.0", "/flashes/expressInstall.swf", null, params);
    $.history.init(loadPage); // history
    var str1 = new String(document.location);
    if (str1.search("#")!=-1){
      var arr1 = str1.split("#");
      var p = arr1[1];
    } else {
      var p = null; 
    }
    if (p==null) {
      var flashvars = {
        url0: "javascript:loadMain('discover');",
        url1: "javascript:loadMain('shop_time-pieces');",
        url2: "javascript:loadMain('shop_time-pieces');",
        url3: "javascript:loadMain('shop_straps');",
        url4: "javascript:loadMain('shop_case-covers');"
      };
      $.swfobject.embedSWF("/flashes/GlamRockSplash.swf", "flash_splash", "100%", "100%", "10.1.0", "/flashes/expressInstall.swf", flashvars, params);     
    } else {
      loadPage(p);
    }
    $("div.sendtofriend a").fancybox({
      'overlayShow':  true,
      'zoomSpeedIn': 0,
      'zoomSpeedOut': 0,
      'frameWidth':   870,
      'frameHeight':  300,
      'itemLoadCallback': openSendToFriend
    });
    $("#box").fancybox({
      'overlayShow':  true,
      'zoomSpeedIn': 0,
      'zoomSpeedOut': 0,
      'frameWidth':   870,
      'frameHeight':  300,
      'itemLoadCallback': openBox
    });
  });
  
  // FLASH FUNCTIONS
  
  var BOXItem = [
    {url: "/", title: ""}
  ];
  
  function openBox(opts) {
    jQuery.each(BOXItem, function(i, val) {
          opts.itemArray.push(val);
      });
  }

  function boxIt(u,t)
  {
    if (t==undefined) t = "";
    BOXItem = [
      {url: ""+u+"", title: ""+t+""}
    ];
    $("#box").click();  
  }

  function boxIt2(u,t)
  {
    if (t==undefined) t = "";
    BOXItem = [
      {url: ""+u+""/*, title: ""+t+""*/, o: {'frameWidth': 610, 'frameHeight': 45}}
    ];
    $("#box").click();  
  }

  function boxIt3(u,t)
  {
    if (t==undefined) t = "";
    BOXItem = [
      {url: ""+u+"", title: ""+t+"", o: {'frameWidth': 620, 'frameHeight': 500}}
    ];
    $("#box").click();  
  }
  
  function boxItNarrow(u,t)
  {
    if (t==undefined) t = "";
    BOXItem = [
      {url: ""+u+""/*, title: ""+t+""*/, o: {'frameWidth': 300, 'frameHeight': 400}}
    ];
    $("#box").click();  
  }

  var STFItem = [
    {url: "sendtofriend.php", title: ""}
  ];
  
  function openSendToFriend(opts) {
    jQuery.each(STFItem, function(i, val) {
          opts.itemArray.push(val);
      });
  }

  function sendtofriend()
  {
    $("div.sendtofriend a").click();  
  }

  function fitstraps()
  {
    boxIt3("/howto.php?img=How-to-FIT-THE-STRAP","HOW TO FIT STRAP");
  }

  function changestraps()
  {
   boxIt3("/howto.php?img=How-to-change-the-strap","HOW TO CHANGE STRAP");
  }

  function cover()
  {
   boxIt3("/howto.php?img=How-to-Change-Cover-Page","HOW TO CHANGE COVER");
  }

  function faq()
  {
   boxIt3("/faq.html","FAQ");
  }
  
  function mailingsignup()
  {
   boxIt("http://shop.glamrockwatches.com/mailing-signup.html","MAILING SIGNUP");
  } 
