//tabbed boxes for descriptions
jQuery(function () {
    var tabContainers = $('div.tabs > div');
    
    jQuery('div.tabs ul.tabNavigation a').click(function () {
        tabContainers.hide().filter(this.hash).show();

        jQuery('div.tabs ul.tabNavigation a').removeClass('selected');
		jQuery(this).addClass('selected');

        
        return false;
    }).filter(':first').click();
});

//sidebar image function for melange and custom collections
jQuery(function () {
    var sidebarImages = $('div.sidebarDesc > div');
    
    jQuery('div.truffle a.descLink').click(function () {
        sidebarImages.hide().filter(this.hash).show();

        jQuery('div.truffle a.descLink').removeClass('selected');
		jQuery(this).addClass('selected');

        
        return false;
    }).filter(':first').click();
});

//popup window for custom collection
jQuery(function () {
    var customForm = $('#popupOrder');
    
//    $('input.tally').click(function () {
           $(function () {
		////////////////////////////////////////////////
		
		var popupStatus = 0;

		//loading popup with jQuery magic!
		jQuery(function loadPopup(){
			//loads popup only if it is disabled
			if(popupStatus==0){
				jQuery("#backgroundPopup").css({
					"opacity": "0.9"
				});
				jQuery("#backgroundPopup").fadeIn("slow");
				jQuery("#popupOrder").fadeIn("slow");
				popupStatus = 1;
			}
		});

		//disabling popup with jQuery magic!
		

		//centering popup
		jQuery(function centerPopup(){
			//request data for centering
			var windowWidth = document.documentElement.clientWidth;
			var windowHeight = document.documentElement.clientHeight;
			var popupHeight = jQuery("#popupOrder").height();
			var popupWidth = jQuery("#popupOrder").width();
			//centering
			jQuery("#popupOrder").css({
				"position": "absolute",
				"top": windowHeight/2-popupHeight/2,
				"left": windowWidth/2-popupWidth/2
			});
			//only need force for IE6

			jQuery("#backgroundPopup").css({
				"height": windowHeight
			});

		});


        ///////////////////////////////////////////////
        return false;
    })
	jQuery('input.goback').click(function () {
		jQuery(function disablePopup(){
			//disables popup 
				jQuery("#backgroundPopup").fadeOut("slow");
				jQuery("#popupOrder").fadeOut("slow");
				popupStatus = 0;
		});
	});
});

//clear button on custom form
function clear_form_elements(ele) {

    jQuery(ele).find(':input').each(function() {
        switch(this.type) {
            case 'password':
            case 'select-multiple':
            case 'select-one':
            case 'text':
			  jQuery(this).val('');
                break;
            case 'textarea':
                jQuery(this).val('');
                break;
            case 'checkbox':
            case 'radio':
                this.checked = false;
        }
    });

}

//hide radio buttons on custom collection popup
jQuery(function(){

		jQuery('ul.12-box li:nth-child(1)').hide();
		jQuery('ul.24-box li:nth-child(1)').hide();
		jQuery('ul.24-box li:nth-child(2)').hide();
		
});



jQuery(document).ready(function () {

	//context sensitive menu for menubar with id of menuID
	var menuID = '#wpm5'
		
	jQuery(menuID + ' ul ul').hide();
	jQuery(menuID + ' li.selected ul').show();
	
	//change image with radio buttons
	if(jQuery('ul.previews li').length == 4){
		var box = 0;

		jQuery('ul.variations li:nth-child(1)').click(function() {
			var box = 1;
			jQuery('ul.previews li.active').removeClass('active');
			jQuery('ul.previews li:nth-child(2)').addClass('active');
		});
		 
		jQuery('ul.variations li:nth-child(2)').click(function() {
			var box = 2;
			jQuery('ul.previews li.active').removeClass('active');
			jQuery('ul.previews li:nth-child(3)').addClass('active');
		});
		
		jQuery('ul.variations li:nth-child(3)').click(function() {
			var box = 3;
			jQuery('ul.previews li.active').removeClass('active');
			jQuery('ul.previews li:nth-child(4)').addClass('active');
		});
	}
	
	//turn off thickbox when add to cart clicked
	jQuery('.gift-note .addtocart').click(function() {
		parent.tb_remove(); 
			
	});
		
	//reload cart after gift card close
	function gift_card_reload_cart() {
		parent.location.reload();
	}
	window.onunload = gift_card_reload_cart;
	
	
}); // end document ready block






	




