// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

var fileFieldCount = 1;

Ajax.Responders.register({
        onCreate: function() {
                if($('notification') && Ajax.activeRequestCount> 0)
                        Effect.Appear('notification',{duration: 0.25, queue: 'end'});
        },
        onComplete: function() {
                hoverProducts();
                if($('notification') && Ajax.activeRequestCount == 0)
                        Effect.Fade('notification',{duration: 0.25, queue: 'end'});
        }
});

function updateUrlField(name, url){
  $(url).value = $(name).value.toLowerCase().replace(/\s/g, "-");
}

function createSelfClearInput(element_class, start_value){
  $$(element_class).each(function(element){
        element.observe('focus', function(event){
            if(element.value==start_value){
              element.value="";
            };
        });
  });
  $$(element_class).each(function(element){
        element.observe('blur', function(event){
            if(element.value==""){
              element.value=start_value;
            };
        });
  });
};

jQuery(document).ready(function(){
    jQuery('.blocks_inside a').mouseenter(function(element){
        jQuery(this).find('span.animated').stop().animate({
          "opacity": "0"
        }, 
        {"duration": "normal"});
        
        jQuery(this).find('img.animated').stop().animate({
          "marginTop": "20px",
          "marginBottom": "22px"
        }, 
        {"duration": "normal"});
        return false;
    });
    
    jQuery('.blocks_inside a').mouseleave(function(element){
        jQuery(this).find('span.animated').stop().animate({
          "opacity": "1"
        }, 
        {"duration": "normal"});
        
        jQuery(this).find('img.animated').stop().animate({
          "marginTop": "0px",
          "marginBottom": "10px"
        }, 
        {"duration": "normal"});
    });
    
    jQuery('.blocks_on_main_page a').mouseenter(function(element){
        jQuery(this).find('span').stop().animate({
          "opacity": "0"
        }, 
        {"duration": "normal"});
        
        jQuery(this).find('img.animated').stop().animate({
          "bottom": "20px"
        }, 
        {"duration": "normal"});
        return false;
    });
    
    jQuery('.blocks_on_main_page a').mouseleave(function(element){
        jQuery(this).find('span').stop().animate({
          "opacity": "1"
        }, 
        {"duration": "normal"});
        
        jQuery(this).find('img.animated').stop().animate({
          "bottom": "0px"
        }, 
        {"duration": "normal"});
    });
    hoverProducts();
});

function hoverProducts(){
  jQuery("#product_box .thumbnails .color_thumbnail").hover(function(){
    var title = jQuery(this).find("a:first").attr("title");
    jQuery(".content table tr td:first-child:contains("+title+")").parent().addClass("selected");
  }, function(){
    var title = jQuery(this).find("a:first").attr("title");  
    jQuery(".content table tr td:first-child:contains("+title+")").parent().removeClass("selected");      
  });
}

jQuery(document).ready(function(){
    jQuery('div.content table.sell_points tr').mouseenter(function(element){
        jQuery(this).addClass("selected");
    });
    jQuery('div.content table.sell_points tr').mouseleave(function(element){
        jQuery(this).removeClass("selected");
    });
});

jQuery(document).ready(function(){
    jQuery('.div_switcher').cycle({
        fx:    'fade', 
        speed:  2500,
        timeout:  10000,
        random:  1,
        pause: 1
    });
    jQuery('.small_div_switcher').cycle({
        fx:    'fade', 
        speed:  2500,
        timeout:  10000,
        random:  1,
        pause: 1
    });
});

jQuery(document).ready(function($) {
  jQuery('a.fancy').facebox() 
})

jQuery(document).ready(function(){
  jQuery('#current_image a').jqzoom({
    zoomWidth: 360,
    zoomHeight: 360,
    xOffset: 0,
    yOffset: 0,
    position: "right"
  });
  
  jQuery(".scroll_to_all").click(function(){
    jQuery.scrollTo('#top_of_a_page','10');
    return false;
  })
  
});

jQuery(document).ready(function(){
    jQuery(".single_product_1 a.unselected").css({'opacity': '0.5'});
    jQuery(".single_product_1 a.unselected").hover(
      function (){
        jQuery(this).stop().animate({opacity: '1'}, 500);
      },
      function (){
        jQuery(this).stop().animate({opacity: '0.5'}, 500);
      }
    );
    jQuery(".single_product_1").hover(
      function (){
        jQuery(this).css({'overflow': 'visible'});
      },
      function (){
        jQuery(this).css({'overflow': 'hidden'});
      }
    );
});
