jQuery.preloader = function(img_src) {
	$("<img>").attr("src", img_src);
}

$(document).ready(function(){
	
	$("#banner").pngFix();
	$(".submenu").pngFix();
	$('ul.sf-menu').superfish().find('ul').bgIframe();
	$("#slideshow").cycle("fade");
	
	$(".sf-menu > li > a").each(function(){
		var path = "/images/header/";
		$(this).parent("li").hover(function(){
			$(this).children("a").children("img").attr("src", path + this.id + "_rollover.jpg");
		}, function(){
			$(this).children("a").children("img").attr("src", path + this.id + ".jpg");
		});
		$.preloader("/images/header/" + $(this).parent("li").attr("id") + "_rollover.jpg");
	});
	
	$('.plus-bar').animate({opacity:0}, 0);
	
	$('#message').css('margin-left', '-50000px');
	$('.plus-bar').click(function(e) {
		e.preventDefault();
		$.ajax({
			url: '/products/addtocart/'+$(e.target).parent().attr('id'),
			success:function(msg) { 
			$('#message').css('margin-left', '370px').show();
			setTimeout("$('#message').fadeOut();", 3000);
				//console.log("Success: "+msg);
			}
		});
	});
	
	$('.textile .label').animate({opacity:0},0);
	
	$('.textile').hover(function() {
		$(this).children('.plus-bar').stop().animate({opacity:1}, 250);
		$(this).children('.label').stop().animate({opacity:1},250);
	}, function() { 
		$(this).children('.plus-bar').stop().animate({opacity:0}, 250);
		$(this).children('.label').stop().animate({opacity:0}, 250);
	});
	
	$("#search_box").focus(function(){
		$(this).css("background", "url('/images/header/serach_bg.png') no-repeat");
	}).blur(function(){
		if (this.value.length <= 0) $(this).css("background", "url('/images/header/serach_bg_focus.png') no-repeat");
	}).css("background", "url('/images/header/serach_bg_focus.png') no-repeat");
	
	$("#search_box_form").submit(function(){
    window.location = "/search/" + $(this).children("input").val();
    return false;
  });

});
