// This is the wp-e-commerce front end javascript "library"

// this function is for binding actions to events and rebinding them after they are replaced by AJAX
// these functions are bound to events on elements when the page is fully loaded.
jQuery(document).ready(function () {
								 
	// Make the product image on the inner page clickable.
	jQuery("div.single_product_display div.image img").wrap("<a class='fancybox' href="+jQuery("div.wpsc_description a").attr('href')+"></a>");
	
	//jQuery("div.poster div.image img").wrap("<a class='fancybox' href="+jQuery("div.wpsc_description a").attr('href')+"></a>");
	
	// Make links in the description fancybox
	jQuery("div.wpsc_description a").addClass("fancybox");
	
	//this bit of code runs on the checkout page. If the checkbox is selected it copies the valus in the billing country and puts it in the shipping country form fields. 23.07.09
	//jQuery('.wpsc_shipping_forms').hide();
     jQuery("#shippingSameBilling, #shippingSameBillingLabel").click(function(){
       				jQuery('.wpsc_shipping_forms').show();
        // If checked
        jQuery("#shippingSameBilling, #shippingSameBillingLabel").livequery(function(){
        
        	if(jQuery("#shippingSameBilling").is(":checked")){    
	            var fname = jQuery("input[title='billingfirstname']").val();
				var lname = jQuery("input[title='billinglastname']").val();            
	            var addr = jQuery("textarea[title='billingaddress']").val();
				var city = jQuery("input[title='billingcity']").val(); 
	            var pcode = jQuery("input[title='billingpostcode']").val();
				var phone = jQuery("input[title='billingphone']").val(); 
	            var email = jQuery("input[title='billingfirstname']").val();
	            var state = jQuery("select[title='billingregion'] :selected").text();
				var country = jQuery("select[title='billingcountry'] :selected").text();
				var countryID = jQuery("select[title='billingcountry'] :selected").val();             
				jQuery("input[title='shippingfirstname']").val(fname);
				jQuery("input[title='shippinglastname']").val(lname); 
				jQuery("textarea[title='shippingaddress']").val(addr);
				jQuery("input[title='shippingcity']").val(city);
				jQuery("input[title='shippingpostcode']").val(pcode);				
				jQuery("input[title='shippingphone']").val(phone);				
				jQuery("input[title='shippingemail']").val(email);		
				jQuery("input[title='shippingstate']").val(state);														
				jQuery("input.shipping_country").val(countryID);
				jQuery("span.shipping_country_name").html(country);
				jQuery("select#current_country").val(countryID);

				jQuery("select[title='shippingcountry']").val(countryID);
				var html_form_id = jQuery("select[title='shippingcountry']").attr('id');
				var form_id =  jQuery("select[title='shippingcountry']").attr('name');
				form_id = form_id.replace("collected_data[", "");
				form_id = form_id.replace("]", "");
				form_id = form_id.replace("[0]", "");
				set_shipping_country(html_form_id, form_id)
				//jQuery("select[title='shippingregion'] :selected").text() = state;				
				if(jQuery("select[title='billingcountry'] :selected").val() != jQuery("select[name='country'] :selected").val()){
					id = jQuery("select[name='country'] :selected").val();
					if(id == 'undefined'){
						jQuery("select[name='country']").val(countryID);
						submit_change_country();
					}
				}
				
				
			}else{

			
			}
         
            //otherwise, hide it
            //jQuery("#extra").hide("fast");
        });
 	 });
	 
	 
	 // Scrollable
	/*jQuery("div.scrollable").scrollable({ 
		size:1,
		autoplay:true,
		loop:true,
		clickable:false
	}).autoscroll({interval:4000, speed:4000, autoplay:true, steps:1 }).circular().navigator({ 
	
		// select #flowtabs to be used as navigator 
        navi: "#poster_nav", 
 
        // select A tags inside the navigator to work as items (not direct children) 
        naviItem: 'a', 
 
        // assign "current" class name for the active A tag inside navigator 
        activeClass: 'current'
	});*/
	 
	 
});