$(document).ready(function() {	
    $('.toggle-value').each(function() {
        var default_value = this.value;
        $(this).focus(function() {
            if(this.value == default_value) {
                this.value = '';
            }
        });
        $(this).blur(function() {
            if(this.value == '') {
                this.value = default_value;
            }
        });
    });
	
	$('.btn-mini-cart a').click(function(e) {
		e.preventDefault();
		$('#mini-cart .items').animate({
			height: 'toggle'
		}, {duration: 100});
	});
	
	$(document).click(function(e) {
		if($(e.target).parents().index($('#mini-cart')) == -1) {
			$('#mini-cart .items').animate({
				height: 'hide'
			}, {duration: 100});
		}
	});	
	
	$('.slideshow').innerfade({ 
		speed: 'slow', 
		timeout: 4000, 
		type: 'sequence', 
		containerheight: '250px'
	});	
	
	$('.tab-link').click(function() {
		$('#product-tabs-container').tabs('select', 0);
		setTimeout(function() { scrollTo(0, $('#product-tabs-container').offset().top); }, 100); // Scroll to word
	
		return false;
	});	
	
	$('a[rel^="prettyPhoto"]').prettyPhoto({
		show_title: false,
		theme: 'facebook',
		overlay_gallery: false
	});
	
	$('#mini-cart .tag').click(function() { 
		var url = $(this).find('a').attr('href'); 
		window.location = url; 
	}); 
	
	$('.datepicker').datepicker({
		minDate: 0,
		changeMonth: true,
		changeYear:  true,
		showOn:      'both',
		buttonImage: '/skin/common_files/images/calendar.png',
		buttonImageOnly: true
	});
	
	$('#b_firstname','#opc_profile').live('change', function() {
		$('input[name=firstname]').val($(this).val());
	});
	
	$('#b_lastname','#opc_profile').live('change', function() {
		$('input[name=lastname]').val($(this).val());
	});
	
	$(".tab_content").hide();
	$("ul.tabs li:first").addClass("active").show();
	$(".tab_content:first").show();

	$("ul.tabs li").click(function() {

		$("ul.tabs li").removeClass("active");
		$(this).addClass("active");
		$(".tab_content").hide();

		var activeTab = $(this).find("a").attr("rel");
		$(activeTab).show();
		return false;
	});	
	
	$('.tabbed-slider').anythingSlider({
		autoPlay			: true,
		autoPlayLocked		: true,
		buildStartStop		: false,
		buildArrows         : false,      // If true, builds the forwards and backwards buttons
		buildNavigation     : false,      // If true, buildsa list of anchor links to link to each panel
		delay               : 6000,      // How long between slideshow transitions in AutoPlay mode (in milliseconds)
		resumeDelay         : 6000,
		animationTime       : 600,       // How long the slideshow transition takes (in milliseconds)
		easing              : "swing"    // Anything other than "linear" or "swing" requires the easing plugin
	});	
	
	$('.tabbed-slider-nav a').click(function(){
		var slide = $(this).attr('rel').substring(1);
		$(this).parents().find('.tabbed-slider').anythingSlider(slide);
		return false;
	});	
	
	$('.ask-question a').click(function(e) {
		e.preventDefault();
		popupOpen($(this).attr('href'));
	});
});
