var flashBoxes;
var SHP5 = {

   init: function()
   {
      //SHP5.cufonReplace();
      SHP5.top();
      SHP5.contentBottom();
      SHP5.contentFooter();
      SHP5.flash();
      SHP5.buttons();
		SHP5.fancy();
   },

   flash: function()
   {
      if($.flash)
      {
         flashBoxes = $.flash.create(
         {
            swf: '/Shop/Flash/boxes2.swf',
            params: {
               wmode: 'transparent'
            },
            flashvars: {
               tourl: '/e-butik'
            }         ,
            height: 323,
            width: 385
         });
      }
   },
	
   fancy: function()
   {
      $("a[rel='fancy']").fancybox({
         'zoomOpacity'			: true,
         'overlayShow'			: true,
         'overlayOpacity'		: 0,
         'hideOnContentClick': 	true
      });
   },


   /*cufonReplace:function()
   {
      Cufon.replace('h1');
      Cufon.replace('h2');
      Cufon.replace('h3');
      Cufon.replace('h4');
   },*/
 

   top: function()
   {
      $(".cssTopContact").hover( 
      function () {
         $(this).animate({top: '21px'}, 300);
      },
      function () {
         $(this).animate({top: '10px'}, 300);
      }
      );
   },

   trialShop: function()
   {
      // fancybox
      $(".tpl-img-link").fancybox({
         'zoomOpacity'   : true,
         'overlayShow'   : true,
         'overlayOpacity'  : 0,
         'frameWidth'   : 1060,
         'frameHeight'   : 700,
         'hideOnContentClick':  false
      });

      $('.tooltip-box').tooltip({
         bodyHandler: function() {
            var sTooltipContentCls = $(this).attr("id");
            return $('.' + sTooltipContentCls).html();
         },
         showURL: false,
         track: true,
         left: 10,
         top: -150,
         delay: 0,
         extraClass: "tooltip-trialshop-boxes"
      });

      $('.tooltip').tooltip({
         bodyHandler: function() {
            var sTooltipContentCls = $(this).attr("id");
            return $('.' + sTooltipContentCls).html();
         },
         showURL: false,
         track: true,
         left: 20,
         top: 0,
         delay: 0,
         extraClass: "tooltip-trialshop-accessories"
      });

      $("img.tooltip-box").click(function(e){
         var sRadioBtnId = $(this).parent('label').attr('for');
         $('#' + sRadioBtnId).attr('checked', true);
      });


      $("#themeLink1").click(function(e){
         $("#divThemeInner").animate({marginTop: '0px'}, 300);
         $("#divThemeButtons a").removeClass("cssButtonSelected");
         $(this).addClass("cssButtonSelected");
         return false;
      });

      $("#themeLink2").click(function(e){
         $("#divThemeInner").animate({marginTop: '-230px'}, 300);
         $("#divThemeButtons a").removeClass("cssButtonSelected");
         $(this).addClass("cssButtonSelected");
         return false;
      });

      $("#themeLink3").click(function(e){
         $("#divThemeInner").animate({marginTop: '-460px'}, 300);
         $("#divThemeButtons a").removeClass("cssButtonSelected");
         $(this).addClass("cssButtonSelected");
         return false;
      });
      
      $("#themeLink4").click(function(e){
         $("#divThemeInner").animate({marginTop: '-690px'}, 300);
         $("#divThemeButtons a").removeClass("cssButtonSelected");
         $(this).addClass("cssButtonSelected");
         return false;
      });      

      $(".cssTheme").hover(
      function () {
         $(this).find("p").animate({height: '35px'}, 300);
      },
      function () {
         $(this).find("p").animate({height: '0px'}, 300);
      }
      );

      $("#divFormSubmitBtn").hover(
      function () {
         $(this).attr("src", "/Shop/Image/Setting/cssTrialshopSubmitOver.png")
      },
      function () {
         $(this).attr("src", "/Shop/Image/Setting/cssTrialshopSubmit.png")
      }
      );

      $("img.tpl-img, .cssTheme span").click(function(e){
         var sRadioBtnId = $(this).parent('label').attr('for');

         $('#' + sRadioBtnId).attr('checked', true);
      });

      $(".cssTheme p a").click(function(e){
         //return false;
      });

      $("#form-trialshop-start").submit(function(e){
         return SHP5.trialShopValidation();
      });


   },

   trialShopValidation: function()
   {

      var field;

      field = document.getElementById("divFormInputName");
      if (field.value == '') {
         alert("Ange butiksnamn.");
         field.focus();
         return false;
      }

      field = document.getElementById("divFormInputEmail");
      if (field.value == '') {
         alert("Ange e-postadress.");
         field.focus();
         return false;
      }
      if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(field.value))) {
         alert("Ogiltig e-postadress.");
         field.focus();
         return false;
      }

      return true;

   },


   inline: function()
   {

   },

   contentBottom: function()
   {
      // li-left
      $(".cssContentBottom ul li.li-left a").click(function(e){
         $(".cssContentBottom ul li.li-left").removeClass("li-selected");
         $(this).parent().addClass("li-selected");
      });

      // li-right
      $(".cssContentBottom ul li").hover(
      function () {
         $(this).addClass("li-hover");
      },
      function () {
         $(this).removeClass("li-hover");
      }
      );

   },


   contentFooter: function()
   {

      $("#cssBoxTrialShopButton").hover(
      function () {
         $(this).attr("src", "/Shop/Image/Setting/cssBoxTrialShopButtonOver.gif");
      },
      function () {
         $(this).attr("src", "/Shop/Image/Setting/cssBoxTrialShopButton.gif");
      }
      );

      $("#cssBoxTrialShopInput").focus(function(e){
         if ($(this).attr("value") == "Vad ska din webbutik heta?")
         $(this).attr("value", "");
      });

   },




   // COMPARE - SHOP SIZE
   compare: function()
   {
      $('.cssFunctionRow').tooltip({
         bodyHandler: function() {
            var sTooltipContentCls = $(this).attr("id");
            return $('.' + sTooltipContentCls).html();
         },
         showURL: false,
         track: true,
         left: 20,
         top: 0,
         delay: 0,
         extraClass: "tooltip-compare"
      });
   },
   
   
   
   // REFERENCES
   references: function()
   {
      $(".reference").hover(
      function() {
         $(this).find("div").fadeIn("fast");
      },
      function() {
         $(this).find("div").fadeOut("fast");
      }
      );

      $(".referenceHref").fancybox({
         'zoomOpacity'			: true,
         'overlayShow'			: true,
         'overlayOpacity'		: 0,
         'frameWidth'			: 700,
         'frameHeight'			: 530,
         'hideOnContentClick' : false
      });

      $(".referenceHref2").fancybox({
         'zoomOpacity'			: true,
         'overlayShow'			: true,
         'overlayOpacity'		: 0,
         'frameWidth'			: 900,
         'frameHeight'			: 600,
         'hideOnContentClick' : true
      });

   },

   buttons: function()
   {

      // submit
      $("#cssPurpleSubmitButton").hover(
         function () {
            $(this).attr("src", "/Shop/Image/Setting/cssBtnSendOver.png")
         },
         function () {
            $(this).attr("src", "/Shop/Image/Setting/cssBtnSend.png")
         }
      );

      $(".cssHoverButtonPrices").hover(
         function () {
            $(this).attr("src", "/Shop/Image/Setting/cssButtonPricesOver.png");
         },
         function () {
            $(this).attr("src", "/Shop/Image/Setting/cssButtonPrices.png");
         }
      );

      $(".cssHoverButtonTry").hover(
         function () {
            $(this).attr("src", "/Shop/Image/Setting/cssButtonTryOver.png");
         },
         function () {
            $(this).attr("src", "/Shop/Image/Setting/cssButtonTry.png");
         }
      );
      
      $(".cssHoverButtonDemo").hover(
         function () { $(this).attr("src", "/Shop/Image/Setting/cssButtonDemoOver.png"); },
         function () { $(this).attr("src", "/Shop/Image/Setting/cssButtonDemo.png"); }
      );

      $(".cssHoverCallSales").hover(
         function () { $(this).attr("src", "/Shop/Image/Setting/BtnBackOverCall.png"); },
         function () { $(this).attr("src", "/Shop/Image/Setting/BtnBackCall.png"); }
      );
   },

   OpenPopupWnd: function(sUrl, iWdtNo, iHgtNo, bIsResizable)
   {
      var iLeftNo = ((screen.width / 2) - (iWdtNo / 2));
      var iTopNo = ((screen.height / (2 - iHgtNo)) / (2 - (iHgtNo / 10)));

      var sFeatures = 'toolbar=yes, location=yes, directories=no, status=yes, menubar=yes, scrollbars='
         + bIsResizable + ', resizable=' + bIsResizable + ', width=' + iWdtNo + ', height=' + iHgtNo
         + ',alwaysRaised=yes, left=' + iLeftNo + ', top=' + iTopNo + ',screenX=0, screenY=0';

      // Close opened window
      if((typeof oWnd !== "undefined") && (!oWnd.closed))
      {
         oWnd.close();
      }

      oWnd = window.open(sUrl, "OpenPopupWnd", sFeatures);
      oWnd.location.href = sUrl;
      oWnd.focus();
   }
}






$(document).ready(function()
{
   // init
   SHP5.init();

   // connect Icon to all rel="external" links
   $('A[rel="external"]').addClass("ext");


   // startpage
   if ($("body").hasClass("index"))
   {
      // What does this piece of code actually do..?
      //$(".cssContentInnerStartPage").html($("#cssHomepageStartPage-1").html());

      // Cycle quoites
      $('.cssContentInnerStartPage .cssQuotes').cycle({
         fx:    'fade',
         speed:  500
      });


      // Replace flash-thing with 3 boxes
      $(".cssBoxes").html(flashBoxes);

      // Activate hoover buttons
      SHP5.buttons();

      // OH NO, IT'S IE6! (if this would be false that is)
      if(typeof document.body.style.maxHeight !== "undefined") {
         // tab click handler
         $(".cssContentBottom ul li.li-left a").click(function(e){
            var sType = $(this).parent().attr('id');

            $(".cssContentInnerStartPage").animate({opacity: 0}, 300, function(){

               AddContent(sType);
               $(".cssContentInnerStartPage").animate({opacity: 0.99}, 100);
               //SHP5.cufonReplace();
               SHP5.buttons();
            });

            return false;
         });

      }
      else
      {
         $(".cssContentInnerStartPage").css('height', 300);
         $(".cssContentInnerStartPage").css('background', 'transparent');
         $(".cssContent").css('height', 300);

         $(".cssButtonTry").html('<a href="/starta-gratis-egen-provbutik" title="Starta en egen gratis provbutik"><img src="/Shop/Image/Setting/cssButtonTry.png" alt="Starta en egen gratis provbutik" /></a>');
         $(".cssButtonPrices").html('<a href="/bestall" title="Prislista för e-handel hos Starweb"><img src="/Shop/Image/Setting/cssButtonPrices.png" alt="Prislista för e-handel hos Starweb" /></a>');

      }
   }

   // trial shop
   if ($("body").hasClass("starta-gratis-egen-provbutik")) {
      SHP5.trialShop();
   }

   // e-butik
   if ($("body").hasClass("e-butik") || $("body").hasClass("e-butik2")) {
      SHP5.compare();
   }

   // references
   if ($("body").hasClass("referenser-natbutik")) {
      SHP5.references();
      
      // Cycle quoites
      $('.cssQuotes').cycle({
         fx:    'fade',
         speed:  500
      });
   }
});






function AddContent(sType)
{
   $(".cssContentInnerStartPage").html($("#cssHomepageStartPage-1").html());
   $(".cssBoxes").html(flashBoxes);

   $('.cssContentInnerStartPage .cssQuotes').cycle({
      fx:    'fade',
      speed:  500
   });


   $(".cssButtonPrices").find("img").hover(
   function () {
      $(this).attr("src", "/Shop/Image/Setting/cssButtonPricesOver.png");
   },
   function () {
      $(this).attr("src", "/Shop/Image/Setting/cssButtonPrices.png");
   }
   );


   $(".cssButtonTry").find("img").hover(
   function () {
      $(this).attr("src", "/Shop/Image/Setting/cssButtonTryOver.png");
   },
   function () {
      $(this).attr("src", "/Shop/Image/Setting/cssButtonTry.png");
   }
   );
}







// launch jQuery on domready
$(document).ready(function(e)
{
   $(function() {
      // Contact sales (Quotation)
      $(".cssBtnCallSales").fancybox({
         'zoomOpacity'			: true,
         'overlayShow'			: true,
         'overlayOpacity'		: 0,
         'frameWidth'			: 590,
         'frameHeight'			: 590,
         'hideOnContentClick' : false
      });
   });
});

