/*
 * Sabramedia jQuery Framework
 * 
 * The following framework file contains:
 
 	Custom Menus - Nick's work
 	Superfish v.1.3.1 - jQuery menu widget
	jLightbox - Used for image gallery
	Reps Map - Custom Built by Nick
	

/* Custom Menus */

// JavaScript Document
$(document).ready(function(){
	$(".nav")
	.superfish({
		animation : { opacity:"show",height:"show"}
	})
	.find(">li:has(ul)") /* .find(">li[ul]") in jQuery less than v1.2 */
		.mouseover(function(){
			$("ul", this).bgIframe({opacity:false});
		})
		.find("a")
			.focus(function(){
				$("ul", $(".nav>li:has(ul)")).bgIframe({opacity:false});
				/* $("ul", $(".nav>li[ul]")).bgIframe({opacity:false});
				   in jQuery less than v1.2*/
			});
});

jQuery(document).ready(function(){

	// Remove the hrefs for the divider
	$('div.divider a#quote').attr('href','#');
	
	$('.line-art-panel').hide();
	$('.quote-panel').hide();
	
	$('#line-art').click(function(){
		$('.photo-panel').hide();
		$('.quote-panel').hide();
		$('.line-art-panel').fadeIn(1600);
		return false;
	});
	
	$('#photos').click(function(){
		$('.line-art-panel').hide();
		$('.quote-panel').hide();
		$('.photo-panel').show('slow');
		return false;
	});
	
	$('img.hm-graphic').fadeIn(1600);
	
	
	$('#quote').click(function(){
		$('.photo-panel').hide();
		$('.line-art-panel').hide();
		$('.quote-panel').fadeIn(1600);
		return false;
	});
	
	$('.player01').dialog({
		autoOpen:false,
		resizable:false,
		stack:false,
		width:725,
		modal:true
	});
	$('.player02').dialog({
		autoOpen:false,
		resizable:false,
		stack:false,
		width:725,
		modal:true
	});
	$('.player03').dialog({
		autoOpen:false,
		resizable:false,
		stack:false,
		width:725,
		modal:true
	});
	
	$('.open-player').click(function(e){
		var playerNumber = $(this).attr('data');
		//console.log(playerNumber);
		$('.player' + playerNumber).dialog('open');
		return false;
	});
});

/*
 * Superfish v1.3.1 - jQuery menu widget
 *
 * Copyright (c) 2007 Joel Birch
 *
 * Dual licensed under the MIT and GPL licenses:
 * 	http://www.opensource.org/licenses/mit-license.php
 * 	http://www.gnu.org/licenses/gpl.html
 *
 */

(function($){
	$.fn.superfish = function(o){
		var $sf = this,
			defaults = {
			hoverClass	: 'sfHover',
			pathClass	: 'overideThisToUse',
			delay		: 800,
			animation	: {opacity:'show'},
			speed		: 'normal'
		},
			over = function(){
				clearTimeout(this.sfTimer);
				clearTimeout($sf[0].sfTimer);
				$(this)
				.showSuperfishUl()
				.siblings()
				.hideSuperfishUl();
			},
			out = function(){
				var $$ = $(this);
				if ( !$$.is('.'+o.bcClass) ) {
					this.sfTimer=setTimeout(function(){
						$$.hideSuperfishUl();
						if (!$('.'+o.hoverClass,$sf).length) { 
							over.call($currents.hideSuperfishUl());
						}
					},o.delay);
				}		
			};
		$.fn.extend({
			hideSuperfishUl : function(){
				return this
					.removeClass(o.hoverClass)
					.find('ul:visible')
						.hide()
					.end();
			},
			showSuperfishUl : function(){
				return this
					.addClass(o.hoverClass)
					.find('>ul:hidden')
						.animate(o.animation,o.speed)
					.end();
			},
			applySuperfishHovers : function(){
				return this[($.fn.hoverIntent) ? 'hoverIntent' : 'hover'](over,out);
			}
		});
		o = $.extend({bcClass:'sfbreadcrumb'},defaults,o || {});
		var $currents = $('li:has(ul)',this).filter('.'+o.pathClass);
		if ($currents.length) {
			$currents.each(function(){
				$(this).removeClass(o.pathClass).addClass(o.hoverClass+' '+o.bcClass);
			});
		}
		var $sfHovAr=$('li:has(ul)',this)
			.applySuperfishHovers(over,out)
			.find('a').each(function(){
				var $a = $(this), $li = $a.parents('li');
				$a.focus(function(){
					over.call($li);
					return false;
				}).blur(function(){
					$li.removeClass(o.hoverClass);
				});
			})
			.end()
			.not('.'+o.bcClass)
				.hideSuperfishUl()
			.end();
		$(window).unload(function(){
			$sfHovAr.unbind('mouseover').unbind('mouseout');
		});
		return this.addClass('superfish').blur(function(){
			out.call(this);
		});
	};
})(jQuery);

/* Reps Map Begins Below */

jQuery(document).ready(function(){
	$('#repsContainer div.rep').hide();
	
	repPopup = function(clicks,ids){
		if(clicks == ''){
			var clicks = 'map#Map';
			var ids = 'div#all';
		}
		$(clicks).click(function(){
			$('div.repDisplayBox').remove();
			var reps = $(ids).clone().show();
			var closeBt = $('<a href="#"></a>')
					.addClass('closeRep')
					.text('Close')
					.click(function(){
						$('div.repDisplayBox').remove();																				  
					});
			var display = $('<div></div>').addClass('repDisplayBox').fadeIn(1600).append(reps).append(closeBt);
			
			$('#salesMap').append(display);
			return false;
		});
	};
	
	clickMap = function(array){
		var i;
		var ret = Array();
		for(i in array){
			ret[i] = array[i].toString();
		}
		return(ret.toString());
	};
	
	var CA = new Array('div#murphy01');
	var GA = new Array('div#whit01','div#whit02','div#whit03');
	var TN = new Array('div#newedge04');
	var FL = new Array('div#newedge03');
	var AL = new Array('div#whit01');
	var NY = new Array('div#carose01','div#carose05');
	var CT = new Array('div#carose01','div#carose04','div#carose05');
	var ME = new Array('div#carose02','div#oh');
	var MA = new Array('div#carose02','div#carose03','div#carose05');
	var NH = new Array('div#carose02');
	var RI = new Array('div#carose02');
	var VT = new Array('div#carose03','div#carose05');
	var NC = new Array('div#roncindy01','div#roncindy02');
	var SC = new Array('div#roncindy01','div#roncindy02');
	var VA = new Array('div#roncindy01','div#roncindy02');
	var WV = new Array('div#roncindy01','div#roncindy02');
	var CO = new Array('div#newedge01','div#newedge02');
	var AZ = new Array('div#newedge01','div#newedge02');
	var NM = new Array('div#newedge01','div#newedge02');
	var UT = new Array('div#newedge01','div#newedge02');
	var OTHERS = new Array('div#all'); 
	
	repPopup('map#Map #CA',clickMap(CA));
	repPopup('map#Map #GA',clickMap(GA));
	repPopup('map#Map #TN',clickMap(TN));
	repPopup('map#Map #FL',clickMap(FL));
	repPopup('map#Map #AL',clickMap(AL));
	repPopup('map#Map #NY',clickMap(NY));
	repPopup('map#Map #CT',clickMap(CT));
	repPopup('map#Map #ME',clickMap(ME));
	repPopup('map#Map #MA',clickMap(MA));
	repPopup('map#Map #NH',clickMap(NH));
	repPopup('map#Map #RI',clickMap(RI));
	repPopup('map#Map #VT',clickMap(VT));
	repPopup('map#Map #NC',clickMap(NC));
	repPopup('map#Map #SC',clickMap(SC));
	repPopup('map#Map #VA',clickMap(VA));
	repPopup('map#Map #WV',clickMap(WV));
	repPopup('map#Map #CO',clickMap(CO));
	repPopup('map#Map #AZ',clickMap(AZ));
	repPopup('map#Map #NM',clickMap(NM));
	repPopup('map#Map #UT',clickMap(UT));
	
	// repPopup('map#Map #IA,#NE,#KS,#MO,#IL,#TX,#AR',clickMap(WEST));
	// Nick's line - repPopup($('map#Map area').not('#TN,#KY,#OH,#WV,#IN,#PA,#IA,#NE,#KS,#MO,#IL,#TX,#FL,#AR'),'div#all');
	repPopup($('map#Map area').not('#CA,#GA,#TN,#FL,#AL,#NY,#CT,#ME,#MA,#NH,#RI,#VT,#NC,#SC,#VA,#WV,#CO,#AZ,#NM,#UT'),clickMap(OTHERS));
});


/* jLightbox Begins Below */

var Lightbox={fileLoadingImage:'../../inc/images/loading.gif',fileBottomNavCloseImage:'../../inc/images/closelabel.gif',overlayOpacity:0.8,resizeSpeed:'normal',borderSize:10,imageArray:new Array,activeImage:0,overlaySpeed:'slow',initialize:function(){Lightbox.updateImageList();$("body").append('<div id="overlay"></div> 			<div id="lightbox"> 				<div id="outerImageContainer"> 					<div id="imageContainer"> 						<img id="lightboxImage" galleryimg="false" /> 						<div style="" id="hoverNav"> 							<a href="#" id="prevLink"></a> 							<a href="#" id="nextLink"></a> 						</div> 						<div id="loading"> 							<a href="#" id="loadingLink"> 								<img src="'+Lightbox.fileLoadingImage+'" /> 							</a> 						</div> 					</div> 				</div> 				<div id="imageDataContainer"> 					<div id="imageData"> 						<div id="imageDetails"> 							<span id="caption"></span> 							<span id="numberDisplay"></span> 						</div> 						<div id="bottomNav"> 							<a href="#" id="bottomNavClose"> 								<img src="'+Lightbox.fileBottomNavCloseImage+'" /> 							</a> 						</div> 					</div> 				</div> 			</div>');$('#overlay').click(function(){Lightbox.end();return false}).hide();$('#lightbox').hide();$('#loadingLink').click(function(){Lightbox.end();return false});$('#bottomNavClose').click(function(){Lightbox.end();return false});$('#outerImageContainer').width(250).height(250);$('#prevLink').css({paddingTop:Lightbox.borderSize,paddingLeft:Lightbox.borderSize});$('#nextLink').css({paddingTop:Lightbox.borderSize,paddingRight:Lightbox.borderSize});$('#prevLink').click(function(){Lightbox.changeImage(Lightbox.activeImage-1);return false});$('#nextLink').click(function(){Lightbox.changeImage(Lightbox.activeImage+1);return false})},updateImageList:function(){var anchors=$('a');var areas=$('area');for(var i=0;i<anchors.length;i++){var anchor=anchors[i];var relAttribute=String(anchor.getAttribute('rel'));if(anchor.getAttribute('href')&&(relAttribute.toLowerCase().match('lightbox'))){anchor.onclick=function(){Lightbox.start(this);return false}}}for(var i=0;i<areas.length;i++){var area=areas[i];var relAttribute=String(area.getAttribute('rel'));if(area.getAttribute('href')&&(relAttribute.toLowerCase().match('lightbox'))){area.onclick=function(){Lightbox.start(this);return false}}}},start:function(imageLink){$("select, embed, object").hide();var arrayPageSize=Lightbox.getPageSize();$('#overlay').width(arrayPageSize[0]).height(arrayPageSize[1]);$('#overlay').css({opacity:Lightbox.overlayOpacity}).fadeIn(Lightbox.overlaySpeed);Lightbox.imageArray=new Array;imageNum=0;var anchors=$(imageLink.tagName);imageLink=$(imageLink);if((imageLink.attr('rel')=='lightbox')){Lightbox.imageArray.push(new Array(imageLink.attr('href'),imageLink.attr('title')))}else{for(var i=0;i<anchors.length;i++){var anchor=$(anchors[i]);if(anchor.attr('href')&&(anchor.attr('rel')==imageLink.attr('rel'))){Lightbox.imageArray.push(new Array(anchor.attr('href'),anchor.attr('title')))}}for(i=0;i<Lightbox.imageArray.length;i++){for(var j=Lightbox.imageArray.length-1;j>i;j--){if(Lightbox.imageArray[i][0]==Lightbox.imageArray[j][0]){Lightbox.imageArray.splice(j,1)}}}while(Lightbox.imageArray[imageNum][0]!=imageLink.attr('href')){imageNum++}}var arrayPageScroll=Lightbox.getPageScroll();var lightboxTop=arrayPageScroll[1]+(arrayPageSize[3]/10);var lightboxLeft=arrayPageScroll[0];$("#lightbox").css({top:lightboxTop,left:lightboxLeft});$("#lightbox").show();Lightbox.changeImage(imageNum)},changeImage:function(imageNum){Lightbox.activeImage=imageNum;$('#loading').show();$('#lightboxImage, #hoverNav, #imageDataContainer, #numberDisplay').hide();imgPreloader=new Image();imgPreloader.onload=function(){$('#lightboxImage').attr('src',Lightbox.imageArray[Lightbox.activeImage][0]);Lightbox.resizeImageContainer(this.width,this.height);if($.browser.msie)imgPreloader.onload=function(){}};imgPreloader.src=Lightbox.imageArray[Lightbox.activeImage][0]},resizeImageContainer:function(imgWidth,imgHeight){this.widthCurrent=$('#outerImageContainer').width();this.heightCurrent=$('#outerImageContainer').height();this.widthNew=(imgWidth+(Lightbox.borderSize*2));this.heightNew=(imgHeight+(Lightbox.borderSize*2));this.wDiff=this.widthCurrent-this.widthNew;this.hDiff=this.heightCurrent-this.heightNew;if(this.hDiff!=0||this.wDiff!=0){$('#outerImageContainer').animate({width:this.widthNew,height:this.heightNew},Lightbox.resizeSpeed,'linear',function(){Lightbox.showImage()})}else{if($.browser.msie){Lightbox.pause(250)}else{Lightbox.pause(100)}Lightbox.showImage()}$('#prevLink, #nextLink').height(imgHeight);$('#prevLink, #nextLink').width(parseInt(imgWidth/2));$('#imageDataContainer').width(this.widthNew)},showImage:function(){$('#loading').hide();$('#lightboxImage').fadeIn(Lightbox.resizeSpeed,Lightbox.updateDetails)},updateDetails:function(){if(Lightbox.imageArray[Lightbox.activeImage][1]){$('#caption').html(Lightbox.imageArray[Lightbox.activeImage][1]).show()}if(Lightbox.imageArray.length>1){$('#numberDisplay').html("Image "+eval(parseInt(Lightbox.activeImage)+1)+" of "+Lightbox.imageArray.length).show()}$("#imageDataContainer").slideDown(Lightbox.resizeSpeed,function(){$('#hoverNav').show();Lightbox.updateNav();var arrayPageSize=Lightbox.getPageSize();$('#overlay').height(arrayPageSize[1]);Lightbox.preloadNeighborImages();Lightbox.enableKeyboardNav()})},updateNav:function(){if(Lightbox.activeImage!=0){$('#prevLink').show()}else{$('#prevLink').hide()}if(Lightbox.activeImage!=(Lightbox.imageArray.length-1)){$('#nextLink').show()}else{$('#nextLink').hide()}},enableKeyboardNav:function(){document.onkeydown=Lightbox.keyboardAction},disableKeyboardNav:function(){document.onkeydown=''},keyboardAction:function(e){if(e==null){keycode=event.keyCode;escapeKey=27}else{keycode=e.keyCode;escapeKey=e.DOM_VK_ESCAPE}key=String.fromCharCode(keycode).toLowerCase();if((key=='x')||(key=='o')||(key=='c')||(keycode==escapeKey)){Lightbox.end()}else if((key=='p')||(keycode==37)){if(Lightbox.activeImage!=0){Lightbox.disableKeyboardNav();Lightbox.changeImage(Lightbox.activeImage-1)}}else if((key=='n')||(keycode==39)){if(Lightbox.activeImage!=(Lightbox.imageArray.length-1)){Lightbox.disableKeyboardNav();Lightbox.changeImage(Lightbox.activeImage+1)}}},preloadNeighborImages:function(){if((Lightbox.imageArray.length-1)>Lightbox.activeImage){preloadNextImage=new Image();preloadNextImage.src=Lightbox.imageArray[parseInt(Lightbox.activeImage)+1][0]}if(Lightbox.activeImage>0){preloadPrevImage=new Image();preloadPrevImage.src=Lightbox.imageArray[parseInt(Lightbox.activeImage)-1][0]}},end:function(){Lightbox.disableKeyboardNav();$('#lightbox').hide();$("#overlay").fadeOut(Lightbox.overlaySpeed);$("select, object, embed").show()},getPageScroll:function(){var xScroll,yScroll;if(self.pageYOffset){yScroll=self.pageYOffset;xScroll=self.pageXOffset}else if(document.documentElement&&document.documentElement.scrollTop){yScroll=document.documentElement.scrollTop;xScroll=document.documentElement.scrollLeft}else if(document.body){yScroll=document.body.scrollTop;xScroll=document.body.scrollLeft}arrayPageScroll=new Array(xScroll,yScroll);return arrayPageScroll},getPageSize:function(){var xScroll,yScroll;if(window.innerHeight&&window.scrollMaxY){xScroll=window.innerWidth+window.scrollMaxX;yScroll=window.innerHeight+window.scrollMaxY}else if(document.body.scrollHeight>document.body.offsetHeight){xScroll=document.body.scrollWidth;yScroll=document.body.scrollHeight}else{xScroll=document.body.offsetWidth;yScroll=document.body.offsetHeight}var windowWidth,windowHeight;if(self.innerHeight){if(document.documentElement.clientWidth){windowWidth=document.documentElement.clientWidth}else{windowWidth=self.innerWidth}windowHeight=self.innerHeight}else if(document.documentElement&&document.documentElement.clientHeight){windowWidth=document.documentElement.clientWidth;windowHeight=document.documentElement.clientHeight}else if(document.body){windowWidth=document.body.clientWidth;windowHeight=document.body.clientHeight}if(yScroll<windowHeight){pageHeight=windowHeight}else{pageHeight=yScroll}if(xScroll<windowWidth){pageWidth=xScroll}else{pageWidth=windowWidth}arrayPageSize=new Array(pageWidth,pageHeight,windowWidth,windowHeight);return arrayPageSize},pause:function(ms){var date=new Date();curDate=null;do{var curDate=new Date()}while(curDate-date<ms)}};$(document).ready(function(){Lightbox.initialize()});