/* FW100.a1 */
/* (c)2009 SugarHill Works LLC - http://www.sugarhillworks.com */
/**
 * A simple querystring parser.
 * Example usage: var q = $.parseQuery(); q.fooreturns  "bar" if query contains "?foo=bar"; multiple values are added to an array. 
 * Values are unescaped by default and plus signs replaced with spaces, or an alternate processing function can be passed in the params object .
 * http://actingthemaggot.com/jquery
 *
 * Copyright (c) 2008 Michael Manning (http://actingthemaggot.com)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 **/
$.parseQuery = function(qs,options) {
	var q = (typeof qs === 'string'?qs:window.location.search), o = {'f':function(v){return unescape(v).replace(/\+/g,' ');}}, options = (typeof qs === 'object' && typeof options === 'undefined')?qs:options, o = $.extend({}, o, options), params = {};
	$.each(q.match(/^\??(.*)$/)[1].split('&'),function(i,p){
		p = p.split('=');
		p[1] = o.f(p[1]);
		params[p[0]] = params[p[0]]?((params[p[0]] instanceof Array)?(params[p[0]].push(p[1]),params[p[0]]):[params[p[0]],p[1]]):p[1];
	});
	return params;
}
var q = $.parseQuery(),
now = new Date(),
copytxt = '';

// -- BEG SITE SETTINGS ----------------------------------------------------------------------------------------
$(function($){
	// COPYRIGHT FOOTER
	copytxt = $('#copy > p:eq(0)').html();
	$('#copy > p:eq(0)').html(copytxt.replace('2009','2009-'+now.getFullYear()));
	
	// SETTINGS FOR SITE-WIDE NAV MENU
	if ($("#smoothcontainer").length > 0) {
		ddsmoothmenu.init({
			mainmenuid: "smoothmenu1", //menu DIV id
			orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
			classname: 'ddsmoothmenu', //class added to menu's outer DIV
			showArrows: false, // will show arrows to indicate submenus. note the arrows load in the browser last.
			//customtheme: ["#1c5a80", "#18374a"],
			contentsource: ["smoothcontainer", rootPath+"shw_menu/menu.html"] //"markup" or ["container_id", "path_to_menu_file"]
		});
	}

	// SETTINGS FOR GENERAL USE VERTICAL SCROLL PANES
	if ($('.scroll-pane').length > 0) {
		$('.scroll-pane').jScrollPane({
			scrollbarWidth: 7, // the width of the created scrollbar in pixels (defaults to 10)
			scrollbarMargin: 0, // [int] - the margin to leave to the left of the scrollbar in pixels (defaults to 5)
			//wheelSpeed [int] - controls how fast the mouse wheel makes the content scroll in pixels (defaults to 18)
			showArrows:true, // controls whether to display arrows for the user to scroll with (defaults to false)
			arrowSize: 0, // the height of the arrow buttons if showArrows=true (calculated from CSS if not provided)
			animateTo: true, // whether to animate when calling scrollTo and scrollBy (defaults to false)
			//dragMinHeight [int] - the minimum height to allow the drag bar to be (defaults to 0)
			//dragMaxHeight: 100, // [int] - the maximum height to allow the drag bar to be (defaults to 99999!)
			//animateInterval [int] - The interval in milliseconds to update an animating scrollPane (default 100)
			//animateStep [int] - The amount to divide the remaining scroll distance by when animating (default 3)
			//maintainPosition [boolean] - Whether the contents of the scroll pane maintains its position when you re-init it(so it doesn't scroll as you add more content) (default true)
			//scrollbarOnLeft [boolean] - Whether the scrollbar should appear on the left hand side of the panes content (make sure your CSS also reflects this)
			reinitialiseOnImageLoad: true // [boolean] - Whether the jScrollPane should automatically re-initialise itself when any contained images are loaded (defaults to false)
		});
	}
	
	// SET UP ROLLOVER ANIMATIONS
	$(".fadeCol").hover( 
		function() {
			if ($(this).parent().hasClass('slctd')) { return false; }
			else { $(this).stop(true, true).animate({color:"#FFF"}, 750); }
		}, 
		function() {
			if ($(this).parent().hasClass('slctd')) { return false; }
			else { $(this).stop(true, true).animate({color:"#D4D4D4"}, 750); }
		}
	);
	$(".fadeBodyCol").hover( 
		function() {
			$(this).stop(true, true).animate({color:"#FFF"}, 750);
		}, 
		function() {
			$(this).stop(true, true).animate({color:"#9D7698"}, 750);
		}
	);
	$(".fadeFtrCol").hover( 
		function() {
			$(this).stop(true, true).animate({color:"#999"}, 750);
		}, 
		function() {
			$(this).stop(true, true).animate({color:"#555"}, 750);
		}
	);


	// SET UP VERTICAL POSITIONING ON INFO PAGES
	// Call this function to vertically center a content container its parent. Takes jq selectors as arguments.
	function vCenter(content_cntr, parent_cntr) {
		if ($(parent_cntr).height() === $(content_cntr).height()) {
			var topPos = $(parent_cntr+' > p:first').css({paddingTop:'0', marginTop:'0'}).offset().top;
			var btmPos = $(parent_cntr+' > p:last').css({paddingBottom:'0', marginBottom:'0'}).offset().top + $(parent_cntr+' > p:last').height();
			var content_h = btmPos - topPos;
			var newTopPos = Math.floor((($(parent_cntr).height() / 2) - (content_h / 2)));
			$(content_cntr).css({paddingTop:newTopPos+'px'});
		}
	}
	if ($("#info_cntr").length > 0) {
		vCenter('#info', '.scroll-pane');
	}
	
	
	// INIT SLIDESHOW
	if ($('#ss_cntr').length > 0) {
		ss_init(ss_image_cntr_id);
	}
	
	// SET UP PUCHASE DIV
	if ($('#purch_cntr_bg').length > 0) {		
		$(function() {

			function togglePurchDiv () {
//				IE FIX: USE FIX IF HAVING UNSOLVABLE CSS/POSITIONING PROBLEMS AT BEG/END OF SLIDE ANIMATIONS
		//		if (isitIE === false) {
					$("#purch_cntr_bg,#purch_cntr").toggle("slide", {direction: "right"}, 1000);
		//		} else { 
		//			$("#purch_cntr_bg").css({filter:'alpha(opacity=55'});
		//			$("#purch_cntr_bg,#purch_cntr").toggle(500);
//					USE THE FOLLOWING TO HIDE/SHOW MANUALLY (NOT TOGGLE)
//					if($("#purch_cntr").position().top <= 0){ // hidden, now show...
//						$("#purch_cntr_bg").toggle("slide", {direction: "left"}, 1000, function(){
//							$("#purch_cntr").show(100);
//						});
//					} else { // showing, now hide...
//						$("#purch_cntr").hide(100, function(){
//							$("#purch_cntr_bg").toggle("slide", {direction: "left"}, 1000);
//						});
//					}
		//		}
			}
			
			
			$('#qty_cntr').hover(
				function(){
					if ($(this).children('#qty_bg').hasClass('fcsd') === false) {
						$(this).children('input').stop(true, true).animate({color:'#000'},750);
						$(this).children('#qty_bg').stop(true, true).fadeTo(750, 1);
					}
				},
				function(){
					if ($(this).children('#qty_bg').hasClass('fcsd') === false) {
						$(this).children('input').stop(true, true).animate({color:'#D4D4D4'},750);
						$(this).children('#qty_bg').stop(true, true).fadeTo(750, 0);
					}
				}
			);
			
			$("#quantity").focus(function(){
					$(this).stop(true, true).animate({color:'#000'},750);
					$('#qty_bg').stop(true, true).fadeTo(750, 1).addClass('fcsd');
			});
			$("#quantity").blur(function(){
					$(this).stop(true, true).animate({color:'#D4D4D4'},750);
					$('#qty_bg').stop(true, true).fadeTo(750, 0).removeClass('fcsd');
			});
			
//			$('#opt0_cntr > p').each(function(){
//				$(this).click(function(){
//					$('.label').css({background:'none'});
//					var i = $('#opt0_cntr > p').index(this);
//					$('#opt0_cntr > p:eq('+i+')').removeClass().addClass('slctd');
//					$('#opt0_cntr > p:not(:eq('+i+'))').removeClass().addClass('deslctd');
//					$('#opt0_cntr > p > .optbg').each(function(){
//						if ($(this).parent().hasClass('slctd')) {
//							$('#os0 > option:eq('+i+')').attr('selected','selected');
//							$('#os0_option_select'+i).val(slideshow[current].option_list_0[i]);
//							$('#os0_option_amount'+i).val(slideshow[current].option_amts_0[i]);
//							$(this).stop(true, true).fadeTo(750, 1);
//						}
//						if ($(this).parent().hasClass('deslctd')) {
//							$(this).stop(true, true).fadeTo(750, 0);
//						}
//					});
//					$('#opt0_cntr > p > a').each(function(){
//						if ($(this).parent().hasClass('slctd')) {
//							$(this).stop(true, true).animate({color:"#000"}, 500);
//						}
//						else if ($(this).parent().hasClass('deslctd')) {
//							$(this).stop(true, true).animate({color:"#D4D4D4"}, 500);
//						}
//					});
//				});
//			}).hover(
//				function() {
//					$(this).children('a').stop(true, true).animate({color:"#000"}, 500);
//					$(this).children('.optbg').stop(true, true).fadeTo(750, 1);
//				}, 
//				function() {
//					$(this).children('a').stop(true, true).animate({color:"#D4D4D4"}, 500);
//					$(this).children('.optbg').stop(true, true).fadeTo(750, 0);
//				}
//			);
			
//			$('#opt1_cntr > p').each(function(){
//				$(this).click(function(){
//									   $('.label').css({background:'none'});
//					var i = $('#opt1_cntr > p').index(this);
//					$('#opt1_cntr > p:eq('+i+')').removeClass().addClass('slctd');
//					$('#opt1_cntr > p:not(:eq('+i+'))').removeClass().addClass('deslctd');
//					$('#opt1_cntr > p > .optbg').each(function(){
//						if ($(this).parent().hasClass('slctd')) {
//							$('#os1 > option:eq('+i+')').attr('selected','selected');
//							$(this).stop(true, true).fadeTo(750, 1);
//						}
//						if ($(this).parent().hasClass('deslctd')) {
//							$(this).stop(true, true).fadeTo(750, 0);
//						}
//					});
//					$('#opt1_cntr > p > a').each(function(){
//						if ($(this).parent().hasClass('slctd')) {
//							$(this).stop(true, true).animate({color:"#000"}, 500);
//						}
//						else if ($(this).parent().hasClass('deslctd')) {
//							$(this).stop(true, true).animate({color:"#D4D4D4"}, 500);
//						}
//					});
//				});
//			}).hover(
//				function() {
//					$(this).children('a').stop(true, true).animate({color:"#000"}, 500);
//					$(this).children('.optbg').stop(true, true).fadeTo(750, 1);
//				}, 
//				function() {
//					$(this).children('a').stop(true, true).animate({color:"#D4D4D4"}, 500);
//					$(this).children('.optbg').stop(true, true).fadeTo(750, 0);
//				}
//			);

			$("#submit_add").hover(
				function() {
					$(this).stop(true, true).animate({color:"#000"}, 500);
					$('#addBtn_bg').stop(true, true).fadeTo(750, 1);
				}, 
				function() {
					$(this).stop(true, true).animate({color:"#D4D4D4"}, 500);
					$('#addBtn_bg').stop(true, true).fadeTo(750, 0);
				}
			);
			
			$("#submit_view").hover( 
				function() {
					$(this).stop(true, true).animate({color:"#000"}, 500);
					$('#viewBtn_bg').stop(true, true).fadeTo(750, 1);
				}, 
				function() {
					$(this).stop(true, true).animate({color:"#D4D4D4"}, 500);
					$('#viewBtn_bg').stop(true, true).fadeTo(750, 0);
				}
			);		
			
			$("#buy_btn_cntr,#purch_close").click(function(){
				togglePurchDiv();
				return false;
			});
		});
	}
	
});
// -- END SETTINGS ----------------------------------------------------------------------------------------

