/* FW100.r1 */
/* (c)2010 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.
 **/
var bioHTML = [];

$.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();

// -- BEG SITE SETTINGS ----------------------------------------------------------------------------------------
$(function($){


	//BOX SHADOW
	function resizeCeibwShdw(init) {
		if (($.browser.msie) && (IEv < 8)) {
			var tgtH = Math.round($(window).height()*0.88);
			var tgtW = Math.round($(window).width());
			var minH = 580;//parseInt($('#ceibw').css('min-height'),10);
			var minW = 1150;
			$('#ceibw').css({width:'95%'});
			if ($('#ceibw').width() < minW) {
				$('#ceibw').css({width:minW+'px'});
			}
			$('#hdr,#ceibw').css({height:((tgtH < minH) ? minH : tgtH)+'px'});
			$('#main_cntr_bg,#scrollPaneImgs,#main_imgs_cntr').css({height:((tgtH < minH) ? minH : tgtH)+'px'});
			if (IEv < 7) {
				$('#hdr').css({left:'15px'});
			}
			
			if (tgtH-50 < minH-50) {
				$('#scrollPaneImgs').css({height:(minH-50)+'px'});
			} else {
				$('#scrollPaneImgs').css({height:(tgtH-50)+'px'});
			}

			posGlass = false;
			var icw =0;
			$('.img_cntr').each(function(i){
				icw+=($(this).outerWidth()+1);
				if (i === current) { posGlass = true; } else { posGlass = false; }
				posImgs(i, img_h_position, img_v_position, posGlass);
			});
			$('#imgs_scr_cntr').css({width:(icw)+'px'});
			$('#main_cntr,#main_cntr_bg,#scrollPaneImgs').css({width:(($('#ceibw').width()-$('#hdr').width()-50)+'px')});
			if (IEv === 7) {
				$('#main_cntr,#main_cntr_bg,#scrollPaneImgs').css({width:(($('#ceibw').width()-$('#hdr').width())+'px')});
				$('#ss_nav_cntr').css({top:'-10px'});
			}

			if(typeof(hScrollImgsInit) == 'function') {
				hScrollImgsInit();
				window.setTimeout('hScrollImgsInit()',500);
			}
		}
		
		$('#ceibw_shdw').css({//top:$('#ceibw').position().top+'px',
							  left:($('#hdr').position().left)+'px',
							  width:($('#hdr').width()+$('#main_cntr').width())+'px',
							  height:$('#ceibw').height() + 'px'
							});
		$('#ceibw_shdw').css({left:($('#hdr').position().left)+'px'});
		$('#ceibw_shdw').css({width:($('#hdr').width()+$('#main_cntr').width())+'px'});
		$('#ceibw_shdw,#main_cntr_bg').css({height:$('#ceibw').height() + 'px'});
		$('#fullscr').css({height:'100%', width:'100%'});
		if ($('#fullscr').width() < 1009) {
			$('#fullscr').css({width:'1009px'});
		}
		if ($('#fullscr').height() < ($('#copy').position().top + $('#copy').height())) {
			$('#fullscr').css({height:($('#copy').position().top + $('#copy').height())+'px'});
		}
	}
	
	// SETTINGS FOR SITE-WIDE NAV MENU
	if ($("#menu_cntr_cntr").length > 0) {
		ddsmoothmenu.init({
			mainmenuid: "menu_cntr", //menu DIV id
			orientation: 'v', //Horizontal or vertical menu: Set to "h" or "v"
			classname: 'nav_menu-v', //class added to menu's outer DIV
			showArrows: false, // will show arrows to indicate submenus. note the arrows load in the browser last.
			contentsource: ["menu_cntr_cntr", rootPath+"shw_menu/nav_menu.html"] //"markup" or ["container_id", "path_to_menu_file"]
		});
	}

	if ($("#menu_cntr_cntr2").length > 0) {
		ddsmoothmenu.init({
			mainmenuid: "menu_cntr", //menu DIV id
			orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
			classname: 'nav_menu-v', //class added to menu's outer DIV
			showArrows: false, // will show arrows to indicate submenus. note the arrows load in the browser last.
			contentsource: ["menu_cntr_cntr2", rootPath+"shw_menu/nav_menu2.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)
			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)
			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').live('mouseover mouseout', function(e) {
	  if (e.type == 'mouseover') {
			$(this).stop(true, true).animate({color:"#039"}, 750);
	  } else {
			$(this).stop(true, true).animate({color:"#000"}, 750);
	  }
	});	
	$(".fadeBodyCol").hover( 
		function() {
			$(this).stop(true, true).animate({color:"#FFF"}, 750);
		}, 
		function() {
			$(this).stop(true, true).animate({color:"#9D7698"}, 750);
		}
	);
	//set up menu link animations
	$(".menuFtrFade").hover( 
		function() { 
			$(this).stop(true, true).animate({color:"#D11"}, 750);
		}, 
		function(){
			$(this).stop(true, true).animate({color:"#DDD"}, 750)
		}
	);
	
	
	
	/*stickyfooter*/
	if ($.browser.safari) {
		$('#copy > p').css({'font-size':'11px'});
	}


	$('#ceibw_shdw').css({top:$('#ceibw').position().top+'px',
						  left:($('#hdr').position().left)+'px',
						  width:($('#hdr').outerWidth()+$('#main_cntr').outerWidth())+'px',
						  height:$('#ceibw').outerHeight()+'px'
						});


			
	// 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();
	}
	

	// 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;
			});
		});
	}
	
	
	
	resizeCeibwShdw(true);
	$( window ).wresize(resizeCeibwShdw);
	$( window ).wresize(posBioOverlay);
	
	
	
	
	// TEXT OVERLAY
	bioHTML[0] = $('#overlay_txt_0').html();
	bioHTML[1] = $('#overlay_txt_1').html();
	bioHTML[2] = $('#overlay_txt_2').html();
 

	$('#overlay').click(function(event){
									if (event.target.nodeName == 'A') {
										return;
									}
									$('#bio_cntr').remove();
									$(this).fadeTo(750, 0, function(){$(this).appendTo('body').hide();});
								 });






});
// -- END SETTINGS ----------------------------------------------------------------------------------------




	function posBioOverlay() {
		if ($('#bio_cntr').length > 0) {
			var bioTop = (($('#overlay').outerHeight() -  $('#bio_cntr').outerHeight()) / 2);
			$('#bio_cntr').css('top', bioTop+'px');
		}
	}	
	function doBioOverlay(num) {
		if ($('#overlay').is(':visible')) {
			var showing = parseInt($('#bio_cntr').attr('rel'),10);
			
			if (showing === num) {
				$('#bio_cntr').remove();
				$('#overlay').fadeTo(750, 0, function(){$(this).appendTo('body').hide();});
			} else {
				$('#bio_cntr').remove();
				$('#overlay').append(bioHTML[num]).appendTo('#main_cntr').fadeTo(750, 1);
				posBioOverlay();
			}
		} else {
			$('#overlay').append(bioHTML[num]).appendTo('#main_cntr').fadeTo(750, 1);
			posBioOverlay();
		}
	}

		






( function( $ )  
{ 
    $.fn.wresize = function( f )  
    { 
        version = '1.1'; 
        wresize = {fired: false, width: 0}; 
 
        function resizeOnce()  
        { 
            if ( $.browser.msie ) 
            { 
                if ( ! wresize.fired ) 
                { 
                    wresize.fired = true; 
                } 
                else  
                { 
                    var version = parseInt($.browser.version,10); 
                    wresize.fired = false; 
                    if ( version < 7 ) 
                    { 
                        return false; 
                    } 
                    else if ( version === 7 ) 
                    { 
                        //a vertical resize is fired once, an horizontal resize twice 
                        var width = $( window ).width(); 
                        if ( width != wresize.width ) 
                        { 
                            wresize.width = width; 
                            return false; 
                        } 
                    } 
                } 
            }
 
            return true; 
        } 
 
        function handleWResize( e )  
        { 
			if ( resizeOnce() ) 
            { 
                return f.apply(this, [e]); 
            } 
        } 
 
        this.each( function()  
        { 
            if ( this == window ) 
            { 
                $( this ).resize( handleWResize ); 
            } 
            else 
            { 
                $( this ).resize( f ); 
            } 
        } ); 
 
        return this; 
    }; 
 
} ) ( jQuery );