 var onceloaded = 0;
jQuery(document).ready(function () {
	var baseurl = window.location.href.split("index.php")[0];
    var loaded = false;
    var content = "";
    var cartload = false;
    var cartdata = "";
    var storeUrl ="";
    
    function getLoadingText(){
    	var loadingText = []
    	loadingText[0] = "Didn't your mama ever teach you that patience is your best virtue?! Good. Please wait...";
    	loadingText[1] = "Hold your horses! We are working hard to load your page...";
    	loadingText[2] = "We get it. You're excited. Please be patient while Wholly Craft makes its grand appearance!";
    	loadingText[3] = "Sit tight! The Wholly Experience is only a few seconds away...";
    	return loadingText[Math.floor(Math.random() * loadingText.length)];
    };
    if (jQuery(".landing").length != 0 && onceloaded == 0) {
    	onceloaded +=1;
        jQuery(".landingdir").remove();
        jQuery(".landingtext").html(getLoadingText() + "<br /><img src='"+baseurl+"skin/frontend/default/default/images/loading.gif' alt='' />");
        jQuery.ajax({ type: "GET", url: baseurl + "index.php/homepage", success: function (data) {
            	jQuery("body").append(data);
            	if (!jQuery.browser.msie){
            		jQuery(".nav a span").fadeTo(0, 0);
            	}
            	jQuery(".nav a img").css({ "height": "0px", "width": "0px" });
                jQuery(".shophere").css("display", "none");
                var numberof = jQuery(data).find("img").length;
                jQuery("img").load(function () {
                    numberof -= 1;
                });
                function loopload() {
                    if (numberof > 0) {
                        setTimeout(loopload, 1000);
                    } else {
                        jQuery(".landingwrap").fadeTo(0, 0, function () {
                            jQuery(this).remove();
                            jQuery(".nav a").each(function () {
                                jQuery("img", this).css({ "margin-left": jQuery("img", this).attr("wide") / 2 + "px", "margin-top": jQuery("img", this).attr("hite") / 2 + "px" })
                                jQuery("img", this).delay((jQuery(this).index() + 1) * 200).animate({ "margin-left": "0px", "margin-top": "0px", "height": jQuery("img", this).attr("hite") + "px", "width": jQuery("img", this).attr("wide") + "px" }, 800, "easeOutBounce", function () {
                                	if (!jQuery.browser.msie){
                                		jQuery(this).siblings().fadeTo(300, 1);
                                	}
                                });
                            });
                        });
                        jQuery(".cover").bind("click", function(){
                        	jQuery(".cover").fadeTo(0, 0, function(){
                        		jQuery(this).css({"width":"0px", "height":"0px"});
                        	});
                        	jQuery(".individual").empty().css("display", "none");
                        });
                    }
                }
                loopload();
        }
        });
    }

    jQuery(".nav a").live("mousedown", function () {
        jQuery("img", this).stop().animate({ "margin-left": jQuery("img", this).attr("wide") / 4 + "px", "margin-top": jQuery("img", this).attr("hite") / 4 + "px", "height": jQuery("img", this).attr("hite") / 2 + "px", "width": jQuery("img", this).attr("hite") / 2 + "px" }, 300);
    }).live("mouseup", function () {
        jQuery("img", this).stop().animate({ "margin-left": "0px", "margin-top": "0px", "height": jQuery("img", this).attr("hite") + "px", "width": jQuery("img", this).attr("hite") + "px" }, 500, "easeOutBounce");
    });
    if (jQuery(".content").length != 0){
    	jQuery(".content").html(jQuery(".content").html().replace(/a:/ig, '<span class="a">A:</span>').replace(/q:/ig, '<span class="q">Q:</span>'));
    }
    jQuery(".content h4").each(function () {
        jQuery(this).attr("hite", jQuery(this).next().height());
        jQuery(this).next().css({ "height": "0px", "overflow": "hidden" });
    }).click(function () {
        if (jQuery(this).next().height() > 20) {
            jQuery(this).next().animate({ "height": "0px" }, 300);
        } else {
            jQuery(this).next().animate({ "height": parseFloat(jQuery(this).attr("hite")) + 20 + "px" }, 300);
            jQuery(this).siblings("h4").next().animate({ "height": "0px" }, 300);
        }
    });
    if (jQuery(".shopnav").length != 0) {
    	var opencat = window.location.href.split("#")[1];
        jQuery.ajax({ type: "GET", url: baseurl + "index.php/advancedcatalog/index/index/id/1/", success: function (data) {
            jQuery(".shopnav").html(data);
            jQuery('h4').each(function(){
            	var getthisone = Math.floor(Math.random()*5);
            	jQuery(this).addClass("h4"+getthisone);    	
            });
            jQuery(".shopnav h4").click(function (e) {
                e.preventDefault();
                var categoryId = jQuery(this).attr("id");
                window.location.hash = categoryId;
                jQuery(".shopitems").fadeTo(0, 0, function () {
                    waitforcart();
                });
                jQuery.ajax({ type: "GET", url: baseurl + "index.php/advancedcatalog/index/products/id/" + categoryId, success: function (data) {
                    cartdata = data;
                    cartload = true;
                }
                });
            });
            jQuery("#"+opencat).trigger("click");
        }
        });
    }
    function waitforcart() {
        if (cartload == false) {
            setTimeout(waitforcart, 100);
        } else {
            cartload = false;
            jQuery(".shopitems").html(cartdata).fadeTo(0, 1);
            jQuery(".category-product").click(function (e) {
                var itemid = jQuery(this).attr("id");
                jQuery(".cover").fadeTo(0,0).css({"width":"100%", "height":"100%"}).fadeTo(0, .6);
                jQuery(".individual").html("<img src='"+baseurl+"skin/frontend/default/default/images/loading.gif' alt='' />").css({"display":"block", "left":(jQuery(window).width() - jQuery(".individual").width())/2+"px", "top": ((jQuery("html").scrollTop() == 0)?jQuery("body").scrollTop():jQuery("html").scrollTop()) + 30 +"px"});
                jQuery.ajax({
                    type: "GET", url: itemid,
                    complete: function (data) {
                    	jQuery(".individual").html(data.responseText + "<div class='closeme'>X</div>");
                    	jQuery(".product-img-box img").click(function(){
                    		jQuery("body").append("<div class='huge'><span></span><img src='"+jQuery(this).attr("big")+"' alt='' /></div>");
                    		jQuery(".huge").click(function(){
                    			jQuery(this).remove();
                    		});
                    	});
                    }
                });
            });
        }
    }
    
    
    
    
    jQuery(".map, .getdirect").click(function (e) {
        e.preventDefault();
        jQuery(".map").animate({ "width": "425px", "height": "350px" }, 300, function () {
            jQuery(this).html('<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?q=3169+N.+High+St.Columbus,+Ohio+43202&amp;ie=UTF8&amp;hq=&amp;hnear=3169+N+High+St,+Columbus,+Franklin,+Ohio+43202&amp;gl=us&amp;ei=KzHLTPLrK8LEngfiq6nXDw&amp;ved=0CBMQ8gEwAA&amp;ll=40.034515,-83.012094&amp;spn=0.023001,0.036478&amp;z=14&amp;iwloc=lyrftr:m,15036538469707858812,40.026826,-83.014691&amp;output=embed"></iframe>');
        });
        jQuery(".getdirect").fadeTo(0, 0);
    });
    
 	jQuery(".btn-cart").live("click", function(e){
 		e.preventDefault();
 		var counted = jQuery("#qty").val();
 		var optionString ="";
 		jQuery(".product-options input, .product-options select, .product-options textarea").each(function(){
 			optionString += "&" + jQuery(this).attr("name")+"="+jQuery(this).val();
 		});
 		jQuery.ajax({type:"GET", url: baseurl+"index.php/checkout/cart/add?product="+jQuery(this).parents("form").find("input[name=product]").attr("value")+"&qty="+ jQuery("#qty").val() + optionString, 
 			success: function(data){
 				var bb1 = data.split('<ul class="messages">')[1];
 				var bb2 = bb1.split('</ul><form')[0];
 			jQuery(".hide").html(bb2);
 			errorText = jQuery(".error-msg li").html();
 			if (jQuery(".error-msg").length == 0){
	 			jQuery(".individual").html( "<span class='success'>"+counted + " Item" +((counted == 1)?" ":"s ") + "added successfully to cart!</span><div class='closeme'>X</div>");
				setTimeout(closeItem, 2000);
 			}else{
 				jQuery(".individual").html("<span class='success'>"+errorText+"<br />Please give us a call at 614.447.3445</span><div class='closeme'>X</div>");
 			}
 			jQuery(".hide").empty();
 		}
		});
 		jQuery(".individual").html("<img src='"+baseurl+"skin/frontend/default/default/images/loading.gif' alt='' />");
 		return false;
 	});
 	jQuery(".cover, .closeme").live("click", function(){
 		closeItem();
 	});
 	function closeItem(){
 		jQuery(".individual").empty().css("display", "none");
 		jQuery(".cover").fadeTo(0, 0, function(){
 			jQuery(this).css({"width":"0px","height":"0px"});
 		});
 		jQuery.ajax({ type: "GET", url: baseurl + "index.php/advancedcatalog/index/products/id/2", success: function (data) {
 			var replacer = data.split("<div")[0];
 			jQuery(".shopcart").replaceWith(replacer);
        }
        });
 	}
});
jQuery(window).load(function () {
});
