//********************************************************
//
//	BEGIN DOCUMENT READY
//
//********************************************************

function form_jump_menu(){
    jQuery(".jumpmenu").change(function() {
    var val = jQuery(this).val();
        if (val != '') {
            location.href=val;
        }
    });
}

jQuery(function($) {
  form_jump_menu();
});


$(function(){

	
	if($('#aux_nav')){
		$('#aux_nav').hover(function(){
			$(this).stop().animate({height: '200px'}, 500).children('li:first').addClass('active');
		},function(){
			$(this).stop().animate({height: '25px'}, 500).children('li:first').removeClass('active');
		});
	}
	
	if($('#email_btn')){	
		$('#email_btn').hover(function(){
			$(this).stop().animate({height: '215px'}, 500).find('.btn').addClass('active');
		}, function(){
			$(this).stop().animate({height: '32px'}, 500).find('.btn').removeClass('active');
		});
	}

	

	
	//********************************************************
	//
	//	HOMEPAGE BACKGROUND SLIDESHOW - only shown on homepage
	//
	//********************************************************
	
	var imArr=new Array(); 
	var host ='http://www.martinomalley.com';
	
	    imArr = ["http://www.martinomalley.com/page/-/site3/homepage_imgs/homepage_education.jpg|http://www.martinomalley.com/issue/issue/education/","http://www.martinomalley.com/page/-/site3/homepage_imgs/homepage_jobs.jpg|http://www.martinomalley.com/issue/issue/jobs/","http://www.martinomalley.com/page/-/site3/homepage_imgs/homepage_fiscal_responsibility.jpg|http://www.martinomalley.com/issue/issue/fiscal_responsibility/","http://www.martinomalley.com/page/-/site3/homepage_imgs/homepage_women_children.jpg|http://www.martinomalley.com/issue/issue/women_and_children/","http://www.martinomalley.com/page/-/site3/homepage_imgs/homepage_small_business.jpg|http://www.martinomalley.com/issue/issue/family_owned_businesses/","http://www.martinomalley.com/page/-/site3/homepage_imgs/homepage_higher_education.jpg|http://www.martinomalley.com/issue/issue/higher_education/","http://www.martinomalley.com/page/-/site3/homepage_imgs/homepage_public_safety.jpg|http://www.martinomalley.com/issue/issue/public_safety/","http://www.martinomalley.com/page/-/site3/homepage_imgs/homepage_environment.jpg|http://www.martinomalley.com/issue/issue/environment/","http://www.martinomalley.com/page/-/site3/homepage_imgs/Minority-Issues-Background-1.jpg|http://www.martinomalley.com/issue/issue/minority_women_owned_businesses/","http://www.martinomalley.com/page/-/site3/homepage_imgs/homepage_healthcare2.jpg|http://www.martinomalley.com/issue/issue/healthcare/","http://www.martinomalley.com/page/-/site3/homepage_imgs/homepage_transportation.jpg|http://www.martinomalley.com/issue/issue/transportation/","http://www.martinomalley.com/page/-/site3/homepage_imgs/homepage_working_families.jpg|http://www.martinomalley.com/issue/issue/working_families/","http://www.martinomalley.com/page/-/site3/homepage_imgs/homepage_veterans.jpg|http://www.martinomalley.com/issue/issue/veterans/","http://www.martinomalley.com/page/-/site3/homepage_imgs/homepage_agriculture.jpg|http://www.martinomalley.com/issue/issue/protecting_family_farms/","http://www.martinomalley.com/page/-/site3/homepage_imgs/homepage_innovation.jpg|http://www.martinomalley.com/issue/issue/leadership_and_innovation/", ];
	
	for (var i in imArr) {
		//alert('key is: ' + i + ', value is: ' + imArr[i]+'<br>');
	}

    bg_tot =imArr.length;


		//fade background image	
		function fadeBG(bg_num){

                          var curr =imArr[bg_num];
                          var mySplitResult = curr .split("|");

                      

			var bg_img	=	'url('+mySplitResult[0]+')';
                   
                             $('#bg_slideshow_overlay').attr("href", mySplitResult[1])

			ss_div.animate({opacity: 0}, 50, function(){
				ss_div.css('background-image',bg_img);

				ss_div.animate({opacity: 1}, 700, function(){
					//preload the next image in the array
						if(bg_num == bg_tot || bg_num == 1) {
							return false;
						} else {
                                                   var next=imArr[(bg_num+1)];
                                                   var mySplitResultNext = curr .split("|");

							$.preLoadImages(host + '/'+ mySplitResultNext[0]);
						}
				});
			});
		}
		
		//Only execute if this is the homepage - variable set by php in header
		if(pagename == 'home'){
		
			$("body").append("<span class='ss_button hidden no_print' id='left_ss_button'>&lt;</span>");
			$("body").append("<span class='ss_button hidden no_print' id='right_ss_button'>&gt;</span>");

			//initial loading animation
			$('#dash_but').delay(2000).animate({top: 20},300, function(){
				$(this).animate({top: 14}, 100);
			});
		
			//preload the bg images
			var cache = [];
			// Arguments are image paths relative to the current page.
			$.preLoadImages = function() {
				var args_len = arguments.length;
				for (var i = args_len; i--;) {
				  var cacheImage = document.createElement('img');
				  cacheImage.src = arguments[i];
				  cache.push(cacheImage);
				}
			};
			
			//variables
			var bg_num		=	0;
			var ss_div		=	$('#bg_slideshow');
			var win_wid		=	$(document).width();
			//var img_path	=	"/page/-/site3/homepage_imgs/homepage_img";
			var nextImg		=	bg_tot; // because we have loaded the first and 2nd images
			

fadeBG(0);






			//preload the 2nd and last images for good measure
			//$.preLoadImages(img_path + "2.jpg", img_path + bg_tot + ".jpg");
			
			//Unhide the control arrows
			$('.ss_button').css('display','block');
			



			//change position of navigation buttons on window resize
			$(window).resize(function() {
			  if($(window).width() <= 960){
				$('#right_ss_button').css('left', '920px');
			  } else {
				$('#right_ss_button').css('right', '0px').css('left', 'auto');
			  }
			});
			



		          //left button
			$('#left_ss_button').bind('click', function(){
				if(bg_num == 0){
					bg_num = bg_tot;
					fadeBG(bg_num);
				} else {
					bg_num -= 1;
					fadeBG(bg_num);
				}
			});
			
			//right button
			$('#right_ss_button').bind('click', function(){
				if(bg_num == bg_tot){
					bg_num = 0;
					fadeBG(bg_num);
				} else {
					bg_num += 1;
					fadeBG(bg_num);
				}
			});



		} else {
			//if it's not the homepage then keep the dash_button in place
			if($('#dash_but')){$('#dash_but').css('top', '14px');}
		}
		
		
	//********************************************************
	//	
	//	SOCIAL MEDIA DASHBOARD
	//
	//********************************************************
	
		$('#dash_but').click(function(){
			if($(this).hasClass('active')){
				$(this).removeClass('active');
				//hide the child objects
				$.hideDashboard();
			} else {
				$(this).addClass('active');
				//close up the billboard area if it's the homepage
				if(pagename == 'home'){
					$.closeBillboard();
				} else {
					$.showDashboard();
				}
			}
			return false;
		});
		
		//hover for input buttons
		$('#dash_but').hover(function(){
			$(this).stop().animate({top: 10},100);
		}, function(){
			$(this).stop().animate({top: 14},100);
		});

	//********************************************************
	//
	//	GET THE FACTS TOGGLE DIV
	//
	//********************************************************	
	
	$('.gtf_expand').click(function(){
		var targ = $(this);
		$.expand_fact(targ);
		return false;
	});
	
	//********************************************************
	//	
	//	HOVER FOR FOOTER LINKS
	//
	//********************************************************
	
	//hover for footer list elements
	$('#footer_bottom ul li a img').hover(function(){
		$(this).stop().animate({opacity: 0.7},100);
	}, function(){
		$(this).stop().animate({opacity: 1},100);
	});

	
});

//********************************************************
//
//	END DOCUMENT READY
//
//********************************************************


	//********************************************************
	//
	//	DASHBOARD FUNCTIONS
	//
	//********************************************************

	$.openBillboard = function(){
		$('#con_map_callout').animate({marginTop: 400},300);
	};	
	
	$.closeBillboard = function(){
		$('#con_map_callout').stop().animate({marginTop: 0},300, function(){
			//show the dashboard once the billboard has closed
			$.showDashboard();
		});
	};
		
	$.showDashboard = function(){

$('a#bg_slideshow_overlay').css('display', 'none');
		$('#dashboard').stop().animate({
			height: 680
		}, 500, function(){
			//make sure children are invisible
			$('#dash_wrap').css('opacity', 0);
			//load the child objects in 
			$.loadSocial();
		});
	};
	
	$.hideDashboard = function(){

$('a#bg_slideshow_overlay').css('display', 'block');
		$('#dash_wrap').delay(200).animate({
				opacity: 0
			}, 300, function(){
			//remove the children from the dashboard
			$(this).empty();
			//close the dashboard
			$('#dashboard').stop().animate({
					height: 0
				}, 500, function(){
				//open back up the billboard area
				if(pagename == 'home'){
					$.openBillboard();
				}
			});
		});
	};
	
	$.loadSocial	=	function() {
		$.ajax({
			url: "/sites/site3/index.php/soc_media",
			cache: false,
			beforeSend: function(){
				$("#loader").fadeIn("fast");
			},
			success: function(html){
				$("#loader").fadeOut("fast", function(){
					$('#dash_wrap').append(html).animate({opacity: 1}, 500);
				});
				
			}
		})		
	};


	//********************************************************
	//
	//	EXPAND FACT FUNCTIONS
	//
	//********************************************************

	$.expand_fact = function(targ){
		if(targ.hasClass('active')){
			targ.removeClass('active').parent().find('.gtf_more').animate({
				opacity: 0
			}, 300, function(){
				$(this).animate({
					height: '0px'
				}, 300, function(){
					targ.text('Click to expand')
				});
			});
		} else {
			targ.addClass('active').parent().find('.gtf_more').animate({
				height: '230px'
			}, 200, function(){
				$(this).animate({
					opacity: 1
				}, 300, function(){
					targ.text('Click to close');
				});
			});
		}
	};














(function($){ 		  
	$.fn.popupWindow = function(instanceSettings){
		
		return this.each(function(){
		
		$(this).click(function(){
		
		$.fn.popupWindow.defaultSettings = {
			centerBrowser:0, // center window over browser window? {1 (YES) or 0 (NO)}. overrides top and left
			centerScreen:0, // center window over entire screen? {1 (YES) or 0 (NO)}. overrides top and left
			height:500, // sets the height in pixels of the window.
			left:0, // left position when the window appears.
			location:0, // determines whether the address bar is displayed {1 (YES) or 0 (NO)}.
			menubar:0, // determines whether the menu bar is displayed {1 (YES) or 0 (NO)}.
			resizable:0, // whether the window can be resized {1 (YES) or 0 (NO)}. Can also be overloaded using resizable.
			scrollbars:0, // determines whether scrollbars appear on the window {1 (YES) or 0 (NO)}.
			status:0, // whether a status line appears at the bottom of the window {1 (YES) or 0 (NO)}.
			width:500, // sets the width in pixels of the window.
			windowName:null, // name of window set from the name attribute of the element that invokes the click
			windowURL:null, // url used for the popup
			top:0, // top position when the window appears.
			toolbar:0 // determines whether a toolbar (includes the forward and back buttons) is displayed {1 (YES) or 0 (NO)}.
		};
		
		settings = $.extend({}, $.fn.popupWindow.defaultSettings, instanceSettings || {});
		
		var windowFeatures =    'height=' + settings.height +
								',width=' + settings.width +
								',toolbar=' + settings.toolbar +
								',scrollbars=' + settings.scrollbars +
								',status=' + settings.status + 
								',resizable=' + settings.resizable +
								',location=' + settings.location +
								',menuBar=' + settings.menubar;

				settings.windowName = this.name || settings.windowName;
				settings.windowURL = this.href || settings.windowURL;
				var centeredY,centeredX;
			
				if(settings.centerBrowser){
						
					if ($.browser.msie) {//hacked together for IE browsers
						centeredY = (window.screenTop - 120) + ((((document.documentElement.clientHeight + 120)/2) - (settings.height/2)));
						centeredX = window.screenLeft + ((((document.body.offsetWidth + 20)/2) - (settings.width/2)));
					}else{
						centeredY = window.screenY + (((window.outerHeight/2) - (settings.height/2)));
						centeredX = window.screenX + (((window.outerWidth/2) - (settings.width/2)));
					}
					window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + centeredX +',top=' + centeredY).focus();
				}else if(settings.centerScreen){
					centeredY = (screen.height - settings.height)/2;
					centeredX = (screen.width - settings.width)/2;
					window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + centeredX +',top=' + centeredY).focus();
				}else{
					window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + settings.left +',top=' + settings.top).focus();	
				}
				return false;
			});
			
		});	
	};
})(jQuery);








