(function( $ ){
	
	var methods = {
		
		init	:	function( options ){
			
			$.extend(settings, options);
			
			return this.each(function(){
				
				var $this = $(this),
				data = $this.data('ssvsAccordian');
				
				if( !data ){
					data = $this.data('ssvsAccordian', settings).data('ssvsAccordian');
				}
				
				methods.start.apply(this);
				
			});
			
		},
		start	:	function(){
			
			var $this = $(this),
			data = $this.data('ssvsAccordian'),
			content = $this.children(data.contentSelector);
			
			
			methods.iCss.apply(content, [{display:'none'}])
			
			$this.find(data.menuSelector).click(function(e){
				e.preventDefault();
				$(this).addClass('ssvs-accordian-selected')
					.siblings().removeClass('ssvs-accordian-selected');
				$(this).next(data.contentSelector).slideToggle('fast');
				
				
			});
			
		},
		iCss	:	function( xCss ){
			
			if(settings.useCss){
				$(this).css(xCss);
			}
			
		}
		
	};
	
	var settings = {
		menuSelector	:	'h3',
		contentSelector	:	'div',
		useCss		:	true
	};
	
	$.fn.ssvsAccordian = function( method ) {
		if ( methods[method] ) {
			
			return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
			
		} else if ( typeof method === 'object' || ! method ) {
			
			return methods.init.apply( this, arguments );
			
		} else {
			
			$.error( 'Method ' +  method + ' does not exist on jQuery.tooltip' );
			
		}
		
		return this;
	}
	
})( jQuery );

$(document).ready(function() {

	$('.shippingradio input[type="radio"]').click(function() {
		
		if ($(this).val() == "pickup" && $(this).attr("checked") != "undefined") {
			$('.pickup').show();	
		} else
			$('.pickup').hide();
		
	});

	/*$('.addtocart').click(function() {

		var id = $(this).attr("name");

		var quantity = $(this).parent().parent().children(".quantity").children().eq(0).val();

		var optID = $(this).siblings(".optID").val();

		var caseFlag = $(this).siblings(".caseFlag").val();

		
		console.log(id);
		

	$.ajax({

		type: "GET",

		url: "./request/addtocart.request.php",

		data: "ID=" + id + "&quantity=" + quantity + "&optID=" + optID + "&case=" + caseFlag,

		success: function(msg){

		}

		});
		

	});*/
	
	$('a.addtocart').each(function(){
		
		$(this).click(function(){
			
			var id = $(this).attr("name");
			
			var quantity = $(this).parent().parent().children(".quantity").children().eq(0).val();
			
			var optID = $(this).siblings(".optID").val();
			
			var caseFlag = $(this).siblings(".caseFlag").val();
			
			if (typeof id == 'undefined') {
				id = '';
			}
			
			if (typeof quantity == 'undefined') {
				quantity = '';
			}
			
			if (typeof optID == 'undefined') {
				optID = '';
			}
			
			if (typeof caseFlag == 'undefined') {
				caseFlag = '';
			}
			
			$.ajax({

				type: "GET",

				url: "./request/addtocart.request.php",

				data: "ID=" + id + "&quantity=" + quantity + "&optID=" + optID + "&case=" + caseFlag

			});
			
		});
	});

	//fancybox

	/* This is basic - uses default settings */

	

	$("a#single_image").fancybox();

	

	/* Using custom settings */

	

	$("a#inline").fancybox({

		'hideOnContentClick': false,

		'hideOnOverlayClick': false,

		'showCloseButton': false

	});

	

	$("a#inlinecart").fancybox({

		'hideOnContentClick': true,

		'showCloseButton': true

	});



	/* Apply fancybox to multiple items */

	

	$("a.group").fancybox({

		'transitionIn'	:	'elastic',

		'transitionOut'	:	'elastic',

		'speedIn'		:	600, 

		'speedOut'		:	200, 

		'overlayShow'	:	false

	});

	

	$('.popup .keepshopping').click(function() {

		$.fancybox.close();

	});



	$(function() {

		$('.eqheight').equalHeights();

	});

	

	/*

	 $('div.secondary_listing').setEqualHeight();

	 $('div.secondary_listing_desc').setEqualHeight();

	 $('div.secondary_listing_desc p').setEqualHeight();

	 */

	//makeEqualHeight($('div.secondary_listing'));

	$('.secondary_listing').equalHeights();

	

	var p = url_value('p');

	if (p == '') 

		p = 175;

	var op = url_value('op');

	

	

	if (p == 2) {

		$("div.secondary_listing_title:eq(0)").css({

			"border-top": "10px solid #d1c100"

		});

		$("div.secondary_listing_title:eq(0)").children("a").css({

			"color": "#d1c100"

		});

		$("div.secondary_listing_desc:eq(0)").children("a.more_info").css({

			"color": "#d1c100"

		});

		

		$("div.secondary_listing_title:eq(1)").css({

			"border-top": "10px solid #d1c100"

		});

		$("div.secondary_listing_title:eq(1)").children("a").css({

			"color": "#d1c100"

		});

		$("div.secondary_listing_desc:eq(1)").children("a.more_info").css({

			"color": "#d1c100"

		});

		

		$("div.secondary_listing_title:eq(2)").css({

			"border-top": "10px solid #d1c100"

		});

		$("div.secondary_listing_title:eq(2)").children("a").css({

			"color": "#d1c100"

		});

		$("div.secondary_listing_desc:eq(2)").children("a.more_info").css({

			"color": "#d1c100"

		});

		

	}

	$("ul#s" + p).show();

	$("ul#s" + op).show();

	//	$("li#"+p).children("img").show();	

	//	$("li#"+op).children("img").show();	

	

	/*$("li.main_nav_cont").mouseover(function(){

	 var ulid = $(this).attr("id");

	 $("ul.secnav").hide();

	 $("li.main_nav_cont").children("img").hide();

	 $("li.main_nav_cont").children("a").css({"color":"#FFF"});

	 $(this).children("a").css({"color":"#FFF"});

	 //		$(this).children("img").show();

	 $("ul#s"+ulid).fadeIn();

	 });*/

	$('#pause').click(function() {

		$('#imgspace').cycle('pause');

		return false;

	});

	$('#play').click(function() {

		$('#imgspace').cycle('resume');

		return false;

	});

	

	$('#feature').hover(function() {

		$('#controls').fadeIn();

		//$('#slideshow').css({"margin":"-31px 0 0 4px"});

	}, function() {

		//$('#slideshow').css({"margin":"-100px 0 0 4px"});

		$('#controls').fadeOut();

		// $('#slideshow').css({"margin":"4px 0 0 4px"});

	

	});

	

	function onAfter(curr, next, opts) {

	}
	
	$('.reqister-form form').submit(function(){
		
		var valid = true;
		$('.register-form-msg').remove();
		$(this).find('input, select').each(function(){
			
			if (typeof $(this).attr('required') !== "undefined" && $(this).val().length <= 0) {
				valid = false;
				$(this).css({border: '1px solid #FF5656'})
					.focus(function(){
						$(this).next('.register-form-msg').remove();
					})
					.after('<span class="register-form-msg">This field is required*</span>');
			}
			
		});
		
		return valid;
		
	});
	
	//$('div.favorite-accordian').ssvsAccordian();
	$('.form-fb form input[type="text"]').focus(function(){
		//jQuery(this).addClass('form-fb-focus-text');
		$(this).css({border:'2px solid #797B84'});
	}).blur(function(){
		$(this).css({border:'1px solid #7F9DB9'});
	});

});



function url_value(name) {

	name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");

	var regexS = "[\\?&]" + name + "=([^&#]*)";

	var regex = new RegExp(regexS);

	var results = regex.exec(window.location.href);

	if (results == null) 

		return "";

	else 

		return results[1];

}



/**

 * Set each object of a group to the same height (the tallest of the group)

 * @param {Object} group

 */

function makeEqualHeight(group) {

	var tallest = 0;

	group.each(function() {

		var thisHeight = $(this).height();

		if (thisHeight > tallest) {

			tallest = thisHeight;

		}

	});

	group.height(tallest);

}



jQuery.fn.setEqualHeight = function(o) {

	var maxHeight = 0;

	var maxElement = null;

	jQuery(this).each(function(i) {

		if ((jQuery(this).height() + parseInt(jQuery(this).css("padding-bottom")) + parseInt(jQuery(this).css("padding-top"))) > maxHeight) {

			maxHeight = jQuery(this).height() + parseInt(jQuery(this).css("padding-top")) + parseInt(jQuery(this).css("padding-bottom"));

			maxElement = this;

		}

	});

	jQuery(this).not($(maxElement)).each(function() {

		$(this).height(maxHeight - parseInt(jQuery(this).css("padding-top")) - parseInt(jQuery(this).css("padding-bottom")))

	})

}



