//Fill URL Form on Product Page for Shipping Quote
function fillURL() {
	document.getElementById('concerning').value = location.href;
	document.getElementById('prodLink').value = location.href;
}

// jQuery Functions
var $j = jQuery.noConflict();



//create todays date
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1;//January is 0!
var yyyy = today.getFullYear();
if(mm<10){mm='0'+mm};//add a 0 to month if less than 10
if(dd<10){dd='0'+dd};//add a 0 to day if less than 10
//var todaysDate = mm+"/"+dd+"/"+yyyy;
var todaysDate = yyyy+"-"+mm+"-"+dd;
//document.write(todaysDate);

//jQuery Carousel
function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

// Best Price Email Mod
function ShowHideEmail(){
	$j("#bestPriceBox").animate({"height": "toggle"}, { duration: 200 });
}

// Toggle Sub Cats
function ShowHideSubCats(){
	$j("#SubCategories").animate({"height": "toggle"}, { duration: 200 });
}

// Toggle Brands
function ShowHideBrands(){
	$j("#SubBrands").animate({"height": "toggle"}, { duration: 200 });
}

$j(document).ready(function() {	
	
	//$j(".jqueryHighlight").fadeTo("slow", 0.3); // This sets the opacity of the thumbs to fade down to 30% when the page loads
	$j(".jqueryHighlight").hover(function(){
	   $j(this).stop().fadeTo(500, 0.65); // This should set the opacity to 100% on hover
    },function(){
 	   $j(this).stop().fadeTo(500, 1.0); // This should set the opacity back to 30% on mouseout
	});
	
	$j("#cartPrice").hide();
	$j(".jqueryCart").hover(function(){
	   $j("#cartPrice").show();
    },function(){
 	   $j("#cartPrice").hide();
	});

	
    $j('#mycarousel').jcarousel({
        vertical: true,
        scroll: 2,
		auto: 2,
		wrap: 'last',
        initCallback: mycarousel_initCallback

    });
	
	$j('#catCar').jcarousel({
        vertical: true,
        scroll: 2
    });
	
	//Parse XML of Event Calendar   
	$j.ajax({
            type: "GET",
            url: "http://www.jimlaabsmusic.com/xml/calendar.xml",
            dataType: "xml",
            success: function(xml) {
                $j(xml).find('events').each(function(){
				    //var dater = $j(this).attr("date");
                    var title = $j(this).find('title').text();
					var when = $j(this).find('when').text();
                    var description = $j(this).find('description').text();
					
					//if the event is past, don't show (uses date from <when> tag in xml
					if (when < todaysDate) {
                    	//show nothing
					} else {
						$j('<h2 class="events_title"></h2>').html(title).appendTo('#events_wrap');
						$j('<div class="events_when"></div>').html(when).appendTo('#events_wrap');
						//$j('<div></div>').html(dater).appendTo('#events_wrap');
                    	$j('<div class="events_description"></div>').html(description).appendTo('#events_wrap');
					}
                });
            }
	});
	
	// Shipping Quote
	$j('#contactform').submit(function(){
		var action = $j(this).attr('action');
		$j('#submit')
			.before('<img src="images/loading.gif" class="loader" />')
			.attr('disabled','disabled');
 
		$j.post(action, { 
			name: $j('#name').val(),
			email: $j('#email').val(),
			phone: $j('#phone').val(),
			concerning: $j('#concerning').val(),
			prodTitle: $j('#prodTitle').val(),
			message: $j('#message').val()
		},
			function(data){
				$j('#contactform #submit').attr('disabled','');
				$j('.response').remove();
				$j('#contactform').before('<span class="response">'+data+'</span>');
				$j('#contactform img.loader').fadeOut(500,function(){$j(this).remove()});
			}
		);
 
		return false;
 
	});
	
	// Best Price email jquery
	$j('#bestPriceEmail').submit(function(){
		var action = $j(this).attr('action');
		$j('#submit2')
			
			.attr('disabled','disabled');
 
		$j.post(action, { 
			email: $j('#email').val(),
			prodLink: $j('#prodLink').val(),
			prodTitle: $j('#prodTitle').val()
		},
			function(data){
				$j('#bestPriceBox #submit2').attr('disabled','');
				$j('.response').remove();
				$j('#bestPriceBox').before('<span class="response" style="color:#FF0000;">'+data+'</span>');

				if(data=='Email sent!') { 
					$j("#bestPriceBox").animate({"height": "toggle"}, { duration: 200 });
					$j(".response").animate({opacity: 0}, { duration: 2000 });
				}
				if(data=='<span style="color:#990000;font-size:8px;">Use a valid email</span>') { 
					$j(".response").animate({opacity: 0}, { duration: 2000 });
				}
			}
		);
 
		return false;
 
	});
	
	
	//jQuery UI Tabs
	$j('#tabs').tabs();
	function runEffect(){
		$j("#tabs").effect('highlight',{},500);
	};
	
	$j("#tabs").ready(function() {
			runEffect();
			return false;
	});


	$j("a[rel='colorbox']").colorbox({maxWidth:"85%", maxHeight:"85%", scalePhotos:true, transition:"elastic", speed: 350});
	
});