$(document).ready(function() {

  /*tellus product slideshow clone*/
  $(".TellusPrdImage").clone().prependTo(".slideshow");    
  
  /*webcam bigpush clone*/
/*  $("#webcam").clone().prependTo(".bigpushsub");
  $(".bigpushsub #webcam").show();*/
  
  /*bokadirekt header clone*/
  $("div.product-info").clone().prependTo("div.product-info-show");
  $("div.product-info-show div.product-info").show();

// Slideshows
  $('.slideshow').cycle({
      fx:     'scrollHorz', 
      speed:  '300', 
      timeout: 10000, 
      pager:  '.pager',
      pause: 1
  });
  $('.big_image').cycle({ 
      fx:     'fade', 
      speed:  'fast', 
      timeout: 0, 
      pager:  '#gallery .nav', 
      pagerAnchorBuilder: function(idx, slide) { 
          // return selector string for existing anchor 
          return '#gallery .nav li:eq(' + idx + ') a'; 
      }
  });

// Slideshow - changer
  $("a.view_1").click(function () {
    $(".viewbar a").removeClass("active");
    $(this).addClass("active");
    $(".slideshow").hide();
    $(".movieshow").hide();
    //$(".googlemap").css("margin",0).show();
    $(".googlemap").css("visibility","visible").show();
    $(".pager").hide();
    return false;
  });
  $("a.view_2").click(function () {
    $(".viewbar a").removeClass("active");
    $(this).addClass("active");
    $(".slideshow").show();
    $(".movieshow").hide();
    $(".googlemap").hide();
    $(".pager").show();
    return false;
  });
  $("a.view_3").click(function () {
    $(".viewbar a").removeClass("active");
    $(this).addClass("active");
    $(".slideshow").hide();
    $(".movieshow").show();
    $(".googlemap").hide();
    $(".pager").hide();
    return false;
  });

// Searchbox 
  $("a#searchme").click(function () { $("#searchbox div").animate({top:'0'},500); return false;});
  $("a#closesearchme").click(function () { $("#searchbox div").animate({top:'-300px'},500); return false; });
        
// TellusProduct Tab-Navigation
  $(".tab:not(:first)").hide();
  $(".tab:first").show();
  $(".htabs a:first").addClass("active");
  
  //when we click one of the tabs
  $(".htabs a").click(function(){
    $(".htabs a").removeClass("active");
    $(this).addClass("active");
    //get the ID of the element we need to show
    stringref = $(this).attr("href").split('#')[1];
    //hide the tabs that doesn't match the ID
    $('.tab:not(#'+stringref+')').hide();
    //fix
    if ($.browser.msie && $.browser.version.substr(0,3) == "6.0") {$('.tab#' + stringref).show();}
    else
      //display our tab fading it in
      $('.tab#' + stringref).fadeIn();
      //stay with me
      return false;
  });       
  /*Kontrollerar URL:en om den är samma som länken (CustomParentLink)*/        
  urlCheck = window.location.pathname + window.location.search;
  $(".hzmenu a[href="+ urlCheck +"]").addClass("active");
  
// SOCIAL MEDIA - SHARES
  fullURL = window.location.href
  title = document.title
  // måste fixa samtliga &-tecken till &amp; samt att fullURL fungerar vid externa länkar.
  $("#sm_facebook").attr({href:"http://www.facebook.com/share.php?u="+fullURL+"&t="+title});
  $("#sm_twitter").attr({href:"http://twitter.com/home?status="+fullURL});
  $("#sm_delicious").attr({href:"http://delicious.com/save?url="+fullURL+"&title="+title});
  $("#sm_email").attr({href:"mailto:?subject=Kolla in "+title+"&body='Länk till sidan:"+fullURL+""});
  
// Calendar startpage - Show value
  $(".calendar-menu li").each(function (i){
    i=i+1;
    if(i<=8){
      $(this).css("display","block");
    }
  });
  
  $(".fancyiframe").fancybox({
	'width'				: '75%',
	'height'			: '75%',
	'autoScale'			: false,
	'transitionIn'		: 'none',
	'transitionOut'		: 'none',
	'titleShow' : false,
	'type'				: 'iframe'
  });



// INACTIVE
// Sorting Umbraco and Tellus submenu's alphabetical
/* var mylist = $('ul.submenu');
    var listitems = mylist.children('li').get();
    listitems.sort(function(a, b) {
       var compA = $(a).text().toUpperCase();
       var compB = $(b).text().toUpperCase();
       return (compA < compB) ? -1 : (compA > compB) ? 1 : 0;
    })
    $.each(listitems, function(idx, itm) { mylist.append(itm); }); 
*/

}); // end document.ready