$(document).ready(function(){	

	// Swap Input Field On Click
	swapValues = [];
    jQuery(".swap_value").each(function(i){
        swapValues[i] = jQuery(this).val();
        jQuery(this).focus(function(){
            if (jQuery(this).val() == swapValues[i]) {jQuery(this).val("");}
        }).blur(function(){
            if (jQuery.trim(jQuery(this).val()) == "") {jQuery(this).val(swapValues[i]);}
        });
    });
	
	// Home Page Banner Cycle
	$('#banner').cycle({
		fx: 'fade',
		timeout: 7000,
		speed: 500
	});
	
	// Drop Down Header Navigation
	$(".drop_down_button").click(function(){
		var dropDown = $(this).attr('href');
		if ($('#drop_down_navigations').children('div:visible').length > 0){
			var tempDrop = $('#drop_down_navigations').children('div:visible').attr('id');
			var currentDrop = '#'+(tempDrop);
			if (dropDown == currentDrop){
				$(this).removeClass('active');
				$(currentDrop).slideUp(700,'easeOutQuad');
				return false;
			};
			$('#header_member p a').removeClass('active');
			$('#navigation ul li a').removeClass('active');
			$('#drop_down_navigations').children('div:visible').slideUp(700,'easeOutQuad');
			$(this).addClass('active');
			$(dropDown).delay(700).slideDown(700,'easeOutQuad');
		} else {
			$(this).addClass('active');
			$(dropDown).slideDown(700,'easeOutQuad');
		};
		return false;
	});	
	
	// Top Slider?
	$('#slide_top').click(function(){
		$('html, body').animate( { scrollTop: 0 }, 'slow' );
		return false;
	});
	
	
	// Docs Page Ajax
	$('#docs_table a.entry').click(function(Event){
		$(Event.target).addClass('loading');
		var Parent = $(Event.target).closest('li');
		var EntryType = $(Event.target).closest('ul').attr('rel');
		
		$('#DocsEntry').empty();
		
		$.get('http://' + window.location.host + '/ajax/'+EntryType+'/' + $(Event.target).attr('rel'), {}, function(rData){
			$(Event.target).removeClass('loading');
			$('#DocsEntry').html(rData);
			$('html,body').animate({scrollTop: jQuery("#DocsEntry").offset().top},'slow');
			colorbox_init();
		});
		
		return false;
	});
	
	// Update Cart Total
	$('#update_total').click(function(Event){		
		var post_params = {};
		$('#checkout select').each(function(){
			post_params[$(this).attr('name')] = $(this).val();
		});

		$(Event.target).parent().find('.loading').show();
	
		$.post('http://' + window.location.host + '/cart/update_quantity/', post_params, function(rData){window.location.reload(true);});
		
		
		
		return false;
	});
	
	// Update Coupon
	$('#coupon_apply').click(function(){
		
		$('#coupon_apply .loading').css('display', 'inline');
	
		$.get('/ajax/apply_coupon/' + $('#cart_coupon').val(), {}, function(){window.location.reload();});
	
		return false;
	});
	
	colorbox_init();
});

function colorbox_init(){

	// Activate Color Box
	$(".colorbox_photo").colorbox({
		maxWidth: "95%", 
		maxHeight: "95%", 
		photoScaling: "true", 
		opacity: .85});
		
	// Another Colorbox one!
	$(".colorbox").colorbox({
		opacity: .85
	});
	
	// More colorbox :)
	$(".colorbox_iframe").colorbox({width:"940px", height:"750px", iframe:true});
	
};
