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

this.imagePreview = function(){	
	/* CONFIG */
		
		xOffset = 50;
		yOffset = 30;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		//var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ this.t +"' alt='Image preview' /></p>");								 
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

jQuery(document).ready(function() {
      
      $('a[@rel*=facebox]').facebox();
      
      $('#facebox #preloader').livequery(function() {
         $(this).hide();   
      });
      
      $('#facebox #product_add_form').livequery(function() {
          $(this).ajaxForm({
            
            beforeSubmit: function(html) {
                  $('#facebox #productadd_form_error').empty();
                  $('#facebox #preloader').show();               
            },
            
            success: function(html){
                  if (html.indexOf("success") != -1)
                  {                                                                        
                        $('#facebox #preloader').hide();
                        jQuery.facebox.close();
                        document.location = html.substr(7).replace(/&amp;/, "&");
                        //alert(html.substr(7));
                  }
                  else
                  {
                        $('#facebox #productadd_form_error').html(html);
                        $('#facebox #preloader').hide();                        
                  }
            }
          });
        });
      
      
      $("#line_img img").mouseover(function(event){
            $(this).css({'cursor':'pointer'});
            
            imgsrc = this.src;          
            numindex = imgsrc.indexOf("t3")-2;
            imgnum = imgsrc.substr(numindex,1);
            $('#big_img1').hide();
            $('#big_img2').hide();
            $('#big_img3').hide();
            switch(imgnum)
            {
            case "1":
              $('#big_img1').show();
              break;    
            case "2":
              $('#big_img2').show();
              break;
            case "3":
              $('#big_img3').show();
            }
      });
      
    
      imagePreview();
      
    
      //alert($('div.fiche').length);
      $('#new_prod_col1 #content .fiche').hide();
      $('#new_prod_col1 #content .fiche').eq(0).show();
      
      $("ul#comingprod_list_li li a.comingprod_link").mouseover(function(event){
         
         var link_index = $("ul#comingprod_list_li li a.comingprod_link").index(this);
         //alert("link_index : " + link_index);
         $('#new_prod_col1 #content .fiche').hide();
         $('#new_prod_col1 #content .fiche').eq(link_index).show();
            
      });
      
      
    
      
      
      
});