jQuery(document).ready(function($) {

      /* LANGUAGE SELECTION */
       
     $('#root_language').hover(function(){
     
           $(this).stop().animate({height: 56}, 200);
     
     },
     function() {
     
          $(this).stop().animate({height: 24}, 200);
     
     }
     );
     
     /* ADULT CONTENT SELECTION */
     
     $('#root_adult').hover(function(){
     
           $(this).stop().animate({height: 56}, 200);
     
     },
     function() {
     
          $(this).stop().animate({height: 24}, 200);
     
     }
     ); 
     
     /* HEADER SLIDESHOW */
     
     $(function(){
     	$('#slide_show div.slide:gt(0)').hide();
     	setInterval(function(){$('#slide_show div.slide:first-child').fadeOut().next('div.slide').fadeIn().end().appendTo('#slide_show');}, 5000);
     });
     
     /* TAGS PRODUCTS HOVER */
          
     $(".grid .item_tags_inner").hover(
     
     function () {
     
     var count = $(this).height();
     
              if(count == 46)
              {
               
                  $(this).parent().stop().animate({height: 54}, 200);
          
               }
               if(count == 69)
              {
               
                  $(this).parent().stop().animate({height: 78}, 200);
          
               }  
     
          },
          function () {
                    
                 $(this).parent().stop().animate({height: 32}, 200);   
          }
     );
     
     /* TAGS PRODUCT DETAIL HOVER */
          
     $(".product_tags").hover(

     function () {

    var count = $(this).height();
     
              if(count == 46)
              {
               
                  $(this).parent().stop().animate({height: 54}, 200);
          
               }
               if(count == 69)
              {
               
                  $(this).parent().stop().animate({height: 78}, 200);
          
               }  
     
          },
          function () {
                    
                 $(this).parent().stop().animate({height: 32}, 200);   
          }
     );
    
    
           /* PRODUCT DETAIL READ MORE TEXT */
       
       $('.product_desc p.read_more').click(function(){
          
          $('.product_desc div.the_more_to_read_text').slideToggle();
          
          $('span.read_more').toggleClass('hide', '');
          
          $('span.read_less').toggleClass('show', '');
       });
       
       $('.widget_text_box p.read_more').click(function(){
          
          $('.widget_text_box div.the_more_to_read_text').slideToggle();
          
          $('span.read_more').toggleClass('hide', '');
          
          $('span.read_less').toggleClass('show', '');
       });
     
       $('.widget_text_box_full p.read_more').click(function(){
          
          $('.widget_text_box_full div.the_more_to_read_text').slideToggle();
          
          $('.widget_text_box_full span.read_more').toggleClass('hide', '');
          
          $('.widget_text_box_full span.read_less').toggleClass('show', '');
       });  
        
     /* Sidebar menu */
     
     $('.active>span').removeClass('up').addClass('down');
     
     $('#category-nav>li>span').click(function (event) {
     
     	var myClass = $(this).attr("class");
          
       
          
     	if(myClass=='down'){
     		$(this).next('ul').stop(true, true).slideUp(300, function() {
     			$(this).prev('span').removeClass('down').addClass('up');
            	});
     	} else {
     		$('#category-nav>li>ul').slideUp(150, function() {
     			$('#category-nav>li>span').removeClass('down').addClass('up');
     		});
     
     
     		//Slide the sub cats down!
     		$(this).next('ul').stop(true, true).slideDown(300, function() {
     
     			// USE FOR ROW DESTINATION!
     			//var dest=$(this).offset().top - 32;
     
     			//$('html,body').animate({scrollTop: 362}, 500);
     			$(this).prev('span').removeClass('up').addClass('down');
            	});
     	}
     });
     
     
     /* COMMENT BOX */
       $('span.show_comment_box').click(function(){
          
          $('.product_leave_comment').slideDown(500); 
          
           var src = '/plugins/captcha/securimage_show.php?' + Math.random(); 
       
       
       $('#captcha').removeAttr("src").attr("src",  src);
          
       });    
        
         $('span.close_comment_box').click(function(){
          
          $('.product_leave_comment').slideUp(500); 
          
       }); 
        
        
       $('.sorter ul li').click(function(){ 
          
          var cssclass = $(this).attr('class');
           
          //alert(cssclass);     
          
          $('#view_'+cssclass).checked = true;
          
          //alert(document.getElementById('view_'+cssclass).attr('checked'));
          
          
       });
       
     // Set tooltips
       
     $("ul.ullang[title]").tooltip({position:'top center',offset: [-8, 9],layout:'<div class="tooltip"><div class="tip-wrap"><span class="tip"></span></div></div>'});
            
     $(".view_titles[title]").tooltip({position:'top center',offset: [-5, 14],layout:'<div class="tooltip2"><div class="tip-wrap"><span class="tip"></span></div></div>'});
     
     $(".rating.with_title[title]").tooltip({position:'top center',offset: [-5, 14],layout:'<div class="tooltip2"><div class="tip-wrap"><span class="tip"></span></div></div>'});
     
     
     // When doc is reay 
     
     $('#slide_show_ready').fadeOut(1000);
     
     
     
     // position header slideshow

     
     keep_sidebar_on_screen();

     resize_and_position();


     setTimeout("$('.overview_items img').fadeIn(800);", 500);
     setTimeout("$('.blog_box img').fadeIn(800);", 500);
     setTimeout("$('.product_image_inner img').fadeIn(800);", 500);
     setTimeout("$('.social_networks_block_overlay').fadeOut(500);", 500);
     setTimeout("$('.social_networks_block_overlay2').fadeOut(500);", 500);
     setTimeout("$('.average_rating_overlay').fadeOut(500);", 500);
     

     $('input.star_rating').rating();
      height_container = $("#container").height();
      
      window.height_sidebar_inner_value = $("#sidebar_inner").height();
     $('#sidebar').height(height_container);
     $('#sidebar').show();
     
     
     
     $('ul#language').hover(function(){

      $("ul#language").stop().animate({height: 64}, 200);

     },
     function() {
     
          $("ul#language").stop().animate({height: 32}, 200);
     
     });
     



   $('#language ul li.nl a').mouseenter(function(){
           
           
            $('#slider_language').stop().animate({
                   marginLeft: '40'
                 }, 500, function() {
                   // Animation complete.
               });
      }
     
    
     
     ).mouseleave(function(){
          
          if($('#language ul li.nl').hasClass('active')){
               $('#slider_language').stop().animate({
                   marginLeft: '40'
                 }, 500, function() {
                   // Animation complete.
               });
          }else{
               $('#slider_language').stop().animate({
                   marginLeft: '0'
                 }, 500, function() {
                   // Animation complete.
               });
          }
          
         
     }
     
    
     );  
    
       $('#language ul li.en a').mouseenter(function(){
           
           
            $('#slider_language').stop().animate({
                   marginLeft: '0'
                 }, 500, function() {
                   // Animation complete.
               });
      }
     
    
     
     ).mouseleave(function(){
          
          if($('#language ul li.en').hasClass('active')){
                $('#slider_language').stop().animate({
                   marginLeft: '0'
                 }, 500, function() {
                   // Animation complete.
               });
          }else{
                $('#slider_language').stop().animate({
                   marginLeft: '40'
                 }, 500, function() {
                   // Animation complete.
               });
          }
          
         
     }
     
    
     );  
     
    $('#windowwaiter').fadeOut(500);
     
});

// When user resizes browser resize elements

$(window).resize(function(){
     resize_and_position();
});

$(document).ready(function() {    
      
	keep_sidebar_on_screen();

});
     
$(window).scroll(function(){			
                          
     keep_sidebar_on_screen();
               
});
          

function resize_and_position(){
       
     var width_window = $('#wrapper').width();
     var width_header = $('#header_inner').width(); 
     var width_differance = width_window - width_header;
     var space_left_right = width_differance / 2;
     
     $('#slide_show_container').css('right', space_left_right);
     
}


function confirmAdult(text) {
  if (confirm(text)) {
    
     document.getElementById('adult').checked = true;     
     document.forms["adult_form"].submit();
     
  }
}

function activate_adult(){
     
     document.getElementById('adult').checked = true;     
     document.forms["adult_form"].submit();

}

function deactivate_adult(){
     
     document.getElementById('no_adult').checked = true;     
     document.forms["adult_form"].submit();

}

function reset_search_form(){

    //function can be called before searchbar is loaded so check if fields exists!!!

    var oTerms = document.getElementById('keyword_search');

    var oCats = document.getElementById('search_categories');

    var oReset = document.getElementById("resetFields");

     var oForm = document.getElementById("form_searchbar");

    if(oTerms == null || oCats == null || oForm == null || oReset == null)
          
          return;

          oTerms.value = '';
          oCats.selectedIndex = 0;
          oReset.value = 1;
          oForm.action = sUrlSelf;
          oForm.submit();
     
     }
     
function load_detail_video(videosrc){ 
     
     $('.product_image_inner img').fadeOut(500);  
     $('.playbutton').fadeOut(500);
     
     setTimeout("$('.product_image_inner').animate({  height: '340px' });", 500);
     setTimeout("$('#videocontainer iframe').attr('src', '"+videosrc+"');", 1000);
     setTimeout("$('#videocontainer iframe').fadeIn(500);", 1000);
     
}

/*
function load_detail_flashvideo(videosrc){
      
          var params = { allowScriptAccess: "always" };
          var atts = { id: "myytplayer" };
     
     swfobject.embedSWF("http://www.youtube.com/e/"+videosrc+"?enablejsapi=2&playerapiid=ytplayer", "ytapiplayer", "670", "340", "8", null, null, params, atts);
     $('.product_image_inner img').fadeOut(500);  
     $('.playbutton').fadeOut(500);
     
     setTimeout("$('.product_image_inner').animate({  height: '340px' });", 500);
     

}
*/

function close_newsletter_overlay(){
     
     $('#newsletter_overlay').fadeOut(300);
     
}



function submit_newsletter(){

      document.newsletter_form.submit();
            
}


function load_youtube_video(code){
       
 
}

function record_detail_fix(){
     
     given_width = $('.product_detaillist').width();
     needed_width = $('.iftobigcutof').width();
     
     console.log(given_width);
     
     
}

