jQuery(document).ready(function() {

jQuery(".datepicker").datepicker();

jQuery("span.tooltip").tooltip({opacity: 0.7});

jQuery(".pop-video").colorbox({iframe:true,opacity:"0.1", innerWidth:640, innerHeight:385});



jQuery(".invoice-recap").click(function() {
 jQuery("#order-recap").hide();
  jQuery("#invoice-recap").show();
  return false;
});

/*
jQuery(".order-recap").click(function() {
 jQuery("#invoice-recap").hide();
 jQuery("#order-recap").show();
 return false;
});
*/



// expand left col width
if(jQuery('.stretch').length > 0) {
	jQuery('.col-main').css("width","95%");
	jQuery('.main').find('.sidebar').addClass('toggle-on');
	jQuery('<a href="" id="menu-toggle" class="show"></a>').insertAfter('.sidebar');
};


// my account side nav toggle
jQuery("#menu-toggle").toggle(
  function () {
  	jQuery(this).parents('.main').find('.sidebar').removeClass('toggle-on');
 	jQuery(this).parents('.main').find('.col-main').css("width","760px");
 	jQuery(this).addClass('hide').removeClass('show');
  },
  function () {
    jQuery(this).parents('.main').find('.col-main').css("width","95%");
	jQuery(this).parents('.main').find('.sidebar').addClass('toggle-on');
 	jQuery(this).addClass('show').removeClass('hide');    
  }
);


// my account hover menu    
   jQuery("a.my-account").parents("li").hover(
 	 function () {
    	
    	jQuery(this).find("ul").show();
  	}, 
 	 function () {
     
     	jQuery(this).find("ul").hide();
    }
);

// Product Page: Option Box


// 
jQuery("#option1").change(function() {
	
	// clear
	jQuery("#option2").hide(); 
	jQuery(".option2-input").text("Choose a Size Option...");
	jQuery("input.radio").attr("checked",false);

	// show the 2nd drop down box
	jQuery(".option2-input").show();
	  
	// hide the 2nd dropdown if nothing is selected  
	if(jQuery(this).val() == "Choose an Option..."){
	  	 jQuery(".option2-input,#option2").hide(); 
	  
	  }

});


jQuery("#option1").click(function() {
	jQuery("#option2").hide(); 
 	  		 
});



jQuery(".option2-input").click(function() {
		 jQuery("#option2").toggle();
		 
		
		 
		 // get the value of Option 1 select box
		 var Opt1Value=jQuery("#option1").val();
	
			
		 //find the class based on the Opt1Value
		 var thisClass=jQuery("#option1 option:contains("+Opt1Value+")").attr('class');
		
		
		 // remove previously assigned radio-block wraps
	     jQuery("#option2 div.radio-block p").unwrap();
	    
	    
		// show the cycle group based on the class selected in Option 1
	    jQuery('.cycle-'+thisClass).show();
	 	jQuery("#option2 p."+thisClass).show();
	    
	    
	    //set the number of options visible in Option2 box
		var numRadios = 10;
	
		 // chunk the items into scrollable groups
	 	jQuery("#option2 div.cycle-"+thisClass).wrapChildren({ 
        	childElem : 'p.'+thisClass , 
       		 sets: numRadios, 
        	wrapper: 'div class="radio-block"'
   	 	});   
    
        
        // find out how many radio-blocks there are
		var numRadioBlocks = jQuery(".radio-block").size();
		

		
	
		
		// goTo starting slide
		if (jQuery("input.radio:checked").length != 0){
			var goToSlide = jQuery("input.radio:checked").parents(".radio-block").index();
		}else{
			var goToSlide=0;
		}
		
		// call jQuery cycle
		jQuery('.cycle-'+thisClass).cycle({ 
   		 fx:     'scrollHorz', 
   		 speed:  'fast', 
   		 timeout: 0, 
   		 next:   '#rad-next', 
   		 prev:   '#rad-prev',
   		 startingSlide: goToSlide,
   		 after:     onAfter

		});

		jQuery("p.goto").text(goToSlide);
	
	    function onAfter(curr,next,opts) {

			// shows page x of x
			var caption = 'Page ' + (opts.currSlide + 1) + ' of ' + opts.slideCount;
			jQuery("h4.slide-count").html(caption);
			jQuery("h4.slide-count").show();
	
			//shows and hides next / prev buttons on first & last slides
			var index = opts.currSlide;
    		jQuery('#rad-prev')[index == 0 ? 'hide' : 'show']();
    		jQuery('#rad-next')[index == opts.slideCount - 1 ? 'hide' : 'show']();
		};
	    
	    
	    // if there's only one radioblock, hide the next/prev & count
	    if(numRadioBlocks == 1){
	    	jQuery('#rad-prev,#rad-next,h4.slide-count').hide();

	    };

		// hide the non-active cycle groups
		jQuery('.cycle-'+thisClass).siblings("div").hide();
		
		
 		 
 		 return false;
		});




jQuery("input.radio").change(function() {

	// display the selected radio value in the option2-input box
	var radioValue = jQuery(this).siblings("label").find("span.desc").text();
	jQuery(".option2-input").text(radioValue);
	
	// hide the drop-down
	jQuery("#option2").hide();		
 	
 	return false;
});




/* NEW DROPDOWN STUFF */

jQuery("dl.last dd:first select").change(function() {
jQuery(".getTest").text("");
//var optionText=jQuery("dd.last select option").text();
//jQuery(".getTest").html(optionText);

 jQuery("dd.last select option:not(:first)").each(function (i) {
 	var optionText=jQuery(this).text();
 	var optionValue=jQuery(this).val();
 	var optionPrice=jQuery(".price-box span.price").text()
 	jQuery(".getTest").append('<br /><a class="puppet" href="" rel="'+optionValue+'">'+optionText+' - '+optionPrice+'</a>');
     
      });
      
    jQuery(".puppet").click(function() {
    	var thisRel=jQuery(this).attr("rel");
    	jQuery(".getTest2").text(thisRel);
    	
    	jQuery("dd.last select option[value='"+thisRel+"']").attr('selected','selected');
  		return false;
	});

	return false;
});


//jQuery("p.numRadioBlocks").text(radioValue);


  
    

/*
(function($) {
    // -------------------------------------------------------------------------
    // INLINE  CONTACT FORMS
    // 
    // Convert all elements with contact-link class to an inline ajax form
    // http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/
    // -------------------------------------------------------------------------
    var contact_form =
        '<div style="display:none">' +
            '<div id="inline-contact" style="padding:10px 20px 10px 10px; background:#fff;">' +
                '<form class="contact-form" action="" method="post" style="margin: 10px 0 0 0;">' +
                '<fieldset>' +
                    '<p>' +
                        '<label>Your e-mail Address <span class="required">*</span></label>' +
                        '<input type="text" tabindex="1" class="validate[required,custom[email]] text medium cr-m" name="email" id="email" value=""/>' +
                    '</p>' +
                    '<p>' +
                        '<label>Subject <span class="required">*</span></label>' +
                        '<input type="text" tabindex="2" class="validate[required] text password medium cr-m" name="subject" id="subject" value=""  style="width: 97.5%"/>' +
                    '</p>' +
                    '<p>' +
                        '<label>Message <span class="required">*</span></label>' +
                        '<textarea name="body" tabindex="3" id="body" class="validate[required] large cr-m"></textarea>' +
                    '</p>' +
                    '<p class="button-box">' +
                        '<button type="submit" class="cr-m">Send Message</button>' +
                    '</p>' +
                '</fieldset>' +
                '</form>' +
            '</div>' +
        '</div>';

    // -------------------------------------------------------------------------

    // Only add this to the source when there are contact links
    if ($('.contact-link')) {
        $('body').append(contact_form);
    }


    $(".contact-link, .contact-box").colorbox({
            width:"600px", 
            inline:true, 
            href:"#inline-contact",
            opacity: .1 ,
            scrolling: false,
            onComplete: function() {
                    var title = $.fn.colorbox.element().attr('title').replace('Contact','');
                    var title_html = title=='' ?  'Send a message' : 'Send a message to: <span style="font-weight: normal; margin-left: 4px">' + title + '</span>';
                    
                    $('#cboxTitle').html(title_html);
                    $('.contact-form').validationEngine({
                            scroll: false,
                            success: function() {
                                    $('#inline-contact button').attr('disabled','disabled').css('opacity','0.3').text('Sending...');
                                    var url = $.fn.colorbox.element().attr('href');
                                    $.ajax({
                                            url: url,
                                            type: "POST",
                                            data: $('#inline-contact .contact-form').serialize(),
                                            success: function(data, status, xhr) {
                                                    $.fn.colorbox.close();
                                                    v.resetForm();
                                            },
                                            error: function(xhr,status,exception){
                                                 alert('There was an error while sending your message');
                                            }
                                    });                
                            }
                    });
            },
            onClosed: function () {
                    $('#inline-contact button').removeAttr('disabled').css('opacity','1').text('Send Message');
                    $.validationEngine.closePrompt('.formError',true)
                    $('.contact-form').get(0).reset();
            }
    });
})(jQuery)
*/

});

