//Fill URL Form on Product Page for Shipping Quote
function fillURL() {
	document.getElementById('concerning').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();
    });
};

$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).fadeTo(500, 0.4); // This should set the opacity to 100% on hover
    },function(){
 	   $j(this).fadeTo(500, 1.0); // This should set the opacity back to 30% on mouseout
	});

	
    $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');
					}
                });
            }
	});
				
	$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('.response').slideDown();
				$j('#contactform img.loader').fadeOut(500,function(){$j(this).remove()});
				if(data=='Message sent!') $j('#contactform').slideUp();
			}
		);
 
		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:"fade"});
	
});