// JavaScript Document
jQuery(document).ready(function($) {

			// hide all ULs inside LI.drawer except the first one
			$('LI.drawer UL').hide();  
			$('LI.defchecks').hide();
			$('LI.defpresc').hide();
			$('#banner').cycle({ fx:'fadeZoom', delay:5000, timeout: 10000, speed:1500, pause: 1 });
			$('#partners').cycle({ fx: 'scrollLeft', delay:5000, speed:400, pause: 1, random: 1});
			var d = '.default-list';
			var x = '';
			var subb = '';

	$.history.init(function(hash){
    	if(hash == "") {
	      // initialize your app
			var path = location.pathname.split("/");
			jQuery(d).addClass('selected').css('display', 'inline');
			

		} else {
			
//			$('#partners').cycle({ fx: 'scrollLeft', delay:5000, speed:400, pause: 1, random: 1});
			//jQuery(d).removeClass('selected').css('display', 'none');
			subb = '';
			//alert( 'load ' + hash);
      	  	var h = '.'+hash+'-list';
	      	// restore the state from hash
		  	jQuery.history.load(hash);
			jQuery('#rightcol ul').removeClass('selected').css('display', 'none');
			jQuery(h).addClass('selected').css('display', 'inline' );			
			
			setDisplay( hash );
			
			

    	}
    },{ unescape: ",/" });
	
	function loadHistory(hash) {
		//alert('loadhistory ' + hash );
		$.history.load(hash);
	};
	
	
	$(".drawer-item a").click(function() {
		jQuery('#rightcol ul').removeClass('selected').css('display', 'none');		
		var href = $(this).attr('href');
		hash = href.replace(/^.*?#/,'');
		//alert('drawer-item a ' + hash);
		if( hash != "" ){
			loadHistory(hash);
		}
		//return false;
 	} );
	
	jQuery("#map-container AREA").mouseover(function(){
				var regionMap = '.'+$(this).attr('id')+'-map';
				var regionList = '.'+$(this).attr('id')+'-list';
				jQuery(regionMap).css('display', 'inline');
				
				// Check if a click event has occured and only change the Region hover state accodringly
				// jQuery('#rightcol ul'
				//if (! jQuery('#map-container img.region').hasClass('selected') ) {
					jQuery('#rightcol ul').removeClass('selected').css('display', 'none');
					jQuery(regionList).css('display', 'inline');
				//}
				
				
			}).mouseout(function(){
				var regionMap = '.'+$(this).attr('id')+'-map';
				var regionList = '.'+$(this).attr('id')+'-list';
				
				
				// Check if a click event has occured and only change the Region hover state accodringly
				if (! jQuery(regionMap).hasClass('selected')) {
					jQuery(regionMap).css('display', 'none');
				}
			
				// Check if a click event has occured and only change the Region hover state accodringly
				if (! jQuery('#map-container img.region').hasClass('selected')) {
					jQuery(regionList).css('display', 'none');
					jQuery(d).addClass('selected').css('display', 'inline');
				}
				else
				{
					jQuery('#rightcol ul').removeClass('selected').css('display', 'none');
					jQuery(x).addClass('selected').css('display', 'inline');
				}
			});

			jQuery("#map-container AREA").click(function(){
				jQuery('#map-container img.region').removeClass('selected').css('display', 'none');
				jQuery('#rightcol ul').removeClass('selected').css('display', 'none');
				jQuery(d).removeClass('selected').css('display', 'none');
				
				var regionMap = '.'+$(this).attr('id')+'-map';
				var regionList = '.'+$(this).attr('id')+'-list';
				x = '.'+$(this).attr('id')+'-list';
				//alert(x);
				//$(address).parameter('lastclicked', $(this).attr('id') );
				
				jQuery(regionMap).addClass('selected').css('display', 'inline');
				jQuery(regionList).addClass('selected').css('display', 'inline');
			});
			
//SCRIPT FOR ADDING SLIDING NAV EFFECT

jQuery('LI.drawer').click(function () {		
		
   		// hide the currently visible drawer contents
	    $('LI.drawer UL:visible').hide();
    	// remove the open class from the currently open drawer
	    $('H2.open').removeClass('open');
	
		///test without next
		var handleOpen = '.'+$(this).attr('id')+'-handle';
		//jQuery('#rightcol ul').removeClass('selected').css('display', 'none');
		$(handleOpen).addClass('open');
		$(handleOpen).next().show();
	
   		 // show the associated drawer content to 'this' (this is the current H2 element)
    // since the drawer content is the next element after the clicked H2, we find
    // it and show it using this:
    //$(this).next().show();
	
    // set a class indicating on the H2 that the drawer is open
    //$(this).addClass('open');
	
		//sets the main text section
		var displayList = '.'+$(this).attr('id')+'-list';
		jQuery('#rightcol ul').removeClass('selected').css('display', 'none');
		jQuery(displayList).addClass('selected').css('display', 'inline' );	
		
		hash = location.hash.replace(/^.*?#/,'');
		//alert('in test ' + hash); 
		if( hash != "" ){
			loadHistory(hash);
				
		}		
		
  });    

function setDisplay( hash ) {
	switch( hash ) {
		case 'busforms':
			hash = 'capabilities';
			break;
		case 'commercial':
			hash = 'capabilities';
			break;
		case 'office':
			hash = 'capabilities';
			break;
		case 'promoitems':
			hash = 'capabilities';
			break;		
		case 'elections':
			hash = 'capabilities';
			break;
		case 'graphic':
			hash = 'capabilities';
			break;
		case 'labels':
			hash = 'capabilities';
			break;
		case 'warehousing':
			hash = 'capabilities';
			break;
		case 'defutil':
			hash = 'defender';
			break
		case 'defchecks':
			hash = 'defender';
			subb = 'defchecks';
			//alert( subb );
			break;
		case 'defchecksprice':
			hash = 'defender';
			subb = 'defchecks';
			break;
		case 'defchecksfeatures':
			hash = 'defender';
			subb = 'defchecks';
			break;
		case 'defpresc':
			hash = 'defender';
			subb = 'defpresc';
			break
		default:
			hash = hash;
	}

	var handleOpen = '.'+hash+'-handle';
	//jQuery(handleOpen).removeClass('open');
	jQuery(handleOpen).addClass('open');
	jQuery(handleOpen).next().show();
    //alert(handleOpen);		   
	//alert('setDiplay ' + hash);
	
	//if hash = defchecks show sub menu
	  	if( subb == 'defchecks' ) {
			$('LI.defchecks').show();
		} else { $('LI.defchecks').hide(); }
		if( subb == 'defpresc' ) {
			$('LI.defpresc').show();
		} else { $('LI.defpresc').hide(); }
		
		if( hash == 'home' ) {
			jQuery('div.testimonials').addClass('selected').css('display', 'inline' );	
		}
		else {
			jQuery('div.testimonials').removeClass('selected').css('display', 'none');
		}
}

});
