function hideCart(){
   $('#modal-cart').css('display', 'none');
   $('#order-form-overlay').css('display', 'none');
   $('#order_product').css('display', 'none');
   $('#jcart-checkout').css('display', 'block');
   $('#master_submit').css('display', 'none');


}
	jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

function tip(elem, classname, msg){
    yOffset = -20;
	xOffset = 20;
	$(elem).hover(function(e){
		$("#tooltip")
			.css("top",(e.pageY + yOffset) + "px")
			.css("left",(e.pageX + xOffset) + "px")
			.html(msg)
			.addClass(classname)
			.css("visibility", "visible");
    },
	function(){
		$("#tooltip").empty().css("visibility", "hidden");
		$("#tooltip").attr("class", "");
    });
	$(elem).mousemove(function(e){
				$("#tooltip")
			.css("top",(e.pageY + yOffset) + "px")
			.css("left",(e.pageX + xOffset) + "px")
	})
}

$(document).ready(function(){



$("body").append("<span id='tooltip'></span>");

$("#cart-broi").change(function(){
  $("#number-of-items").html($("#cart-broi").val())
})

//$("#content").append("<span id='bottom_angles'><!-- --></div>");



$("#navigation-bar a").each(function(){
	var ahtml = $(this).html();
	$(this).html(ahtml + "<span>" + ahtml + "</span>");
});

	function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',h=document.getElementsByTagName('html')[0],b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3')?g+' ff3':is('gecko/')?g:/opera(\s|\/)(\d+)/.test(ua)?'opera opera'+RegExp.$2:is('konqueror')?'konqueror':is('chrome')?w+' '+s+' chrome':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);

 $(".ie6 .category .product:nth-child(3n+1)").before("<div style='clear:both;height:1px;overflow:hidden'><!-- --></div>");

  /* apenda na jquery ne 6te da ba4ka pod ie6/7 */
if($("#content").length > 0){
	    var bottom_angles = document.createElement("span");
		bottom_angles.setAttribute("id", "bottom_angles");
		document.getElementById("content").appendChild(bottom_angles);
}

    $("a.zoom").append("<div id='product-overlay'><!-- --></div>");

	zoomg_width = $(".zoom").width();
	$(".product-thumbnails").css("width", zoomg_width - 6);


  
  $("#form_close").click(function(){
  		$("#order_product").hide();
  		$("#order-form-overlay").hide();
		$("#contact-form-overlay").hide();
        $("#contact-form-overlay").css({"opacity":".7", "filter":"alpha(opacity=70)"});
		$("#contact-form-overlay p").remove();
        $("#promo").hide();

  });




$(".product-thumbnails img").click(function(){
 $("#loadingd").show();
  $("#product-overlay").show();
  		$(".product-thumbnails img").removeClass("active");
  		var tsrc = $(this).attr("alt");
		var longDesc = $(this).attr("longdesc");
  		$(".product-image img:first").attr("src", tsrc);
		$("a.zoom").attr("href", longDesc);
        $("#zoomViewImg").attr("src", longDesc);
		$(this).addClass("active");
        $("#last-thumb").load(function(){
        	$(this).show()
		});
        var preload_zoom = new Image();

		preload_zoom.onload = function(){
 $("#loadingd").hide();
 $("#product-overlay").hide();
		}
preload_zoom.src = longDesc;
  });



  //$(".product-profile .product").append("<div class='bottom_angles'><!-- --></div>");


$("#head-view-cart, #head-cart-number").click(function(){
	$("#modal-cart, #order-form-overlay").show();								
});

$("#main-product-image").mousedown(function(){return false;})



//parent.location.href = window.location.href;

  /* Preload */

$.preload = function(){
  for(var i = 0; i<arguments.length; i++){
    $("<img>").attr("src", arguments[i]);
  }
}
$.preload(
  img_dir+'/addtocarth.jpg',
  img_dir+'/modalcart.png',
  img_dir+'/modal_cart_bottom.png',
  img_dir+'/checkouth.jpg',
  img_dir+'/checkout.jpg',
  img_dir+'/continuesh.jpg',
  img_dir+'/continues.jpg',
  img_dir+'/countrydowna.jpg',
  img_dir+'/countrydown.jpg',
  img_dir+'/order_input.jpg',
  img_dir+'/forder.jpg',
  img_dir+'/rtooltip.png',
  img_dir+'/alertok.jpg',
  img_dir+'/forderh.jpg'
);

$(window).load(function(){

    $.preload(
      img_dir+'/addtocarth.jpg',
      img_dir+'/modalcart.png',
      img_dir+'/modal_cart_bottom.png',
      img_dir+'/checkouth.jpg',
      img_dir+'/checkout.jpg',
      img_dir+'/continuesh.jpg',
      img_dir+'/continues.jpg',
      img_dir+'/countrydowna.jpg',
      img_dir+'/countrydown.jpg',
      img_dir+'/order_input.jpg',
      img_dir+'/forder.jpg',
      img_dir+'/rtooltip.png',
      img_dir+'/forderh.jpg'
    );

})


// Zoom


$("#product-5 br:first").remove();

$("#navigation-bar a, #sidebar a, #footer-nav, .category .product-image a").click(function(){




});


    $.fn.exists = function(){
    	return $(this).length>0;
    	return $(this)=obj;
    }
    $.fn.unexists = function(){
    	return $(this).length==0;
    	return $(this)!=obj;
    }




var ID = $("span.ID");
ID.each(function(){
	$(this).html($(this).html().replace("22a", "22<sup>α</sup>"));
	$(this).html($(this).html().replace("22α", "22<sup>α</sup>"));
    $(this).html($(this).html().replace("a", "<sup>a</sup>"));
    $(this).html($(this).html().replace("e", "e "));
    $(this).html($(this).html().replace("c", "c "));
    $(this).html($(this).html().replace("g", "Г "));
	$(this).css("visibility", 'visible');
});



/*$(".category .product").mouseover(function(){
	$(this).find(".description").css("height", "40px")
});
$(".category .product").mouseout(function(){
	$(this).find(".description").css("height", "0px")
});*/

$(".search-result:odd").addClass("search_result_even");




	$("#about-us-navigation li:last-child a").addClass("last");

    $("#Popular-Categories").prepend("<div id='phov'><!-- --></div>");

    /*$("#Popular-Categories li").hover(function(){
        var index = $("#Popular-Categories li").index(this);
		$("#phov").show();
		var pspeed = 200;
		if(index==0){$("#phov").stop();$("#phov").animate({top: '48px'}, pspeed);}
        if(index==1){$("#phov").stop();$("#phov").animate({top: '72px'}, pspeed);}
        if(index==2){$("#phov").stop();$("#phov").animate({top: '97px'}, pspeed); }
        if(index==3){$("#phov").stop();$("#phov").animate({top: '120px'}, pspeed);}
        if(index==4){$("#phov").stop();$("#phov").animate({top: '144px'}, pspeed);}

	});*/




$("#head-cart-images em.item-obj").livequery('mouseover', function(){
$(this).find(".jcart-remove").css("visibility", "visible")													  
})

$("#head-cart-images em.item-obj").livequery('mouseout', function(){
		$(this).find(".jcart-remove").css("visibility", "hidden")																	
})

$(".the_title").append("<samp>&nbsp;</samp>")

$("#recentlyAdded li").mouseover(function(){ //hovera ne raboti
        $("#recentlyAdded li").removeClass("hover");
		$(this).addClass("hover")
})

$("#about-us-navigation li").hover(function(){
	$(this).addClass("hover")
}, function(){
    	$(this).removeClass("hover")
});

$(".item-obj").each(function(){
	$(this).clone(true).prependTo("#head-cart-images");
})

if($('#head-cart-images em').length>7){$('#head-cart-images').attr('class','head-cart-images-scroll')}

$("#jcart-checkout").click(function(){
	$("#order_product").slideDown("slow", function(){
	  $("#jcart-checkout").hide();
	  $("#master_submit").css("display", "block");

	});

});

$("#head-checkout").click(function(){
	$("#modal-cart").show();
	$("#order-form-overlay").show();

	$("#modal-cart").show();
    $("#jcart-checkout").hide();

	$("#order_product").slideDown("slow", function(){

      $("#master_submit").css("display", "block");

      var form_top = $("#order_product").offset().top;
      $("html, body").animate({scrollTop: form_top})

	});

									
});


$("#master_submit").click(function(){
	var products_to_send = $("#cart_form").html();
    $("#products_to_send").val(products_to_send);

	$("#order_product").submit();
});





$("#recentlyAdded li").prepend("<samp>&nbsp;</samp>");

tip("span.r", "rtip", "The product is not available, but it can be purchased with similar color, or exact, if the color is homogeneous.");
}); //end doc ready



$(window).load(function(){
   	zoomg_width = $(".zoom").width();

    $("#container").css("visibility", "visible");
    $("#onload-overlay").animate({"opacity":"0"}, function(){
      $(this).hide();
    });
    $("#page-loading").hide();

	$(".product-thumbnails").css("width", zoomg_width - 6);

              var mpimgw = $(".product-thumbnails").width();
                   $("#order-info-tabs").width(686 - 8 - mpimgw);
                   $("#order-info-tabs").css({'opacity': '1'});




    $(".ID").attr("style", "visibility:visible !important");
	var phov = new Image();
	phov.src = 'http://wroughtironbg.com/wp-content/themes/wroughtironbg/images/phov.png';

    if($("#main-product-image").exists()){

	        //preload first big image
		$("#loadingd").show();
		$("#product-overlay").show();
		var new_big_src = $("a.zoom").attr("href");
		var preload_big_image = new Image();
	    preload_big_image.src = new_big_src;
	    preload_big_image.onload = function(){
	         $("#loadingd").hide();
			 $("#product-overlay").hide();
			 $("#wrapper").animate({opacity: 1});
	         $("#wrapper").css("visibility", "visible");
		}

	}


});



/*function logomagic(){
	$("#logo").animate({opacity: 0.7}, 800, function(){
         $("#logo").animate({opacity: 1}, 800);
	});
}

setInterval("logomagic()", 10000);

function no_chat(){
	$("script[src*='http://wroughtironbg.com.woopra-ns.com/ping/cookie']").remove();
}
setInterval("no_chat()", 120000);
*/

function qty(){
$('#number-of-items').html($('#cart-broi').val());
}

setInterval("qty()", 300);

/*LIGHBOX*/
$(document).ready(function(){
    	$("a.ironbox, a.zoom").click(function(){
			if($("#WIMiddle_right").width()<$("#WIload").width()){
               $("#WIMiddle_right").css("width", $("#WIload").width());
               $("#WIMiddle_right").css("height", $("#WIload").height());
			}
			$("#WIOverlay").show();
			var scroll_top = $(window).scrollTop();
			$("#WIBox").css("top", (scroll_top + 50));
            $("#WIImg").fadeOut();
			$("#WIBox").css({"visibility":"visible", "left":"50%"});
			$("#WIload").show();
			$("a#WIclose").css({"top":"0px", "height":"0px"});
            var WI_href = $(this).attr("href");
			var NI = new Image();
			NI.onload = function(){
				$("#WIload").hide();
            	var NIsrc = this.src;
                $("#WIImg").attr("src", NIsrc);
                $("#WIImg").hide();
				var WIImg_width = $("#WIImg").width();
                var WIImg_height = $("#WIImg").height();
                var scroll_top = $(window).scrollTop();
                $("#WIBox").css("top", (scroll_top + 50));
                $("#WIMiddle_right").animate({"width":(WIImg_width-20), "height":(WIImg_height-20)}, function(){
                	$("#WIImg").fadeIn();
					$("a#WIclose").animate({"top": "-33px", "height": "25px"});
				});
                $("#WIBox").animate({"marginLeft": -(WIImg_width/2)});
				$("#WIBox").show()
			}
            NI.src = WI_href;
			return false;
		});
       $("a#WIclose, #WIOverlay").click(function(){
            $("#WIBox").css({"visibility":"visible", "left":"-9999px"});
			$("a#WIclose").css({"top":"0px", "height":"0px"});
			$("#WIImg").removeAttr("src");
            $("#WIMiddle_right").removeAttr("style");
            $("#WIBox").css("marginLeft", "-40px");
			$("#WIOverlay").hide();
	   });
	});



function refresh(){
  window.location.href="?";
}

function emptycart(){
  $.cookie("PHPSESSID", null);
}

function cart_on(){
	var hour = 1/24;
	$.cookie("cart", "cart_on", {expires:hour});
	void(0);
}

function cart_off(){
	$.cookie("cart", "cart_off");
	void(0);
}



/*  Validate  */



//check empty
function require(the_form){
    the_form.find(".required").each(function(){
      if($(this).val()=="" || $(this).val()==$(this).attr("title")){
        $(this).addClass("error");
        $(this).parents("div:first").addClass("error");
        $(this).parents("form").addClass("error");
      }
      else{
        $(this).removeClass("error");
        $(this).parents("div:first").removeClass("error");
        $(this).parents("form").removeClass("error");
      }
    });
}

//check email
function checkMail(the_form){
      the_form.find(".required-email").each(function(){
          var thismail = $(this);
          var thismailval = $(this).val();
          var regexmail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;

          if (regexmail.test(thismailval)){
              thismail.removeClass("error");
              thismail.parents("div:first").removeClass("error");
              thismail.parents("form").removeClass("error");
          }
          else{
             thismail.addClass("error");
             thismail.parents("div:first").addClass("error");
             thismail.parents("form").addClass("error");
          }
    })
}


// EXTERNALS:




$(document).ready(function(){

$("form.validate").submit(function(){
    oform = $(this);
    var valid=true;

    require(oform);

    checkMail(oform);

    //checkCaptcha();


    //Final check
    if(oform.find(".error").length>0){
        oform.addClass("error");
        valid=false;
    }
    else{
        oform.removeClass("error");
        valid=true;
    }
    oform.addClass("submitet");

  return valid;
});




// Custom keyUp


$("form.validate .required").bind("keyup blur", function(){
    if($(this).parents("form").hasClass("submitet")){
      if($(this).val()=="" || $(this).val()==$(this).attr("title")){
        $(this).addClass("error");
        $(this).parents("div:first").addClass("error");
      }
      else{
        $(this).removeClass("error");
        $(this).parents("div:first").removeClass("error");
      }
    }
});

$("form.validate .required-email").bind("keyup blur", function(){
    if($(this).parents("form").hasClass("submitet")){
      var thismail = $(this);
      var thismailval = $(this).val();
      var regexmail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
      if (regexmail.test(thismailval)){
          thismail.removeClass("error");
          thismail.parents("div:first").removeClass("error")
      }
      else{
         thismail.addClass("error");
         thismail.parents("div:first").addClass("error");
      }
    }
});




});




















