// AddThis Variables
var addthis_pub="gsnorcal";
var addthis_hover_delay = 200;


$(document).ready( function() {


// Detect IE 6 and forward to "upgrade" page
jQuery.each(jQuery.browser, function(i, val) {
	if(i=="msie" && val == true && parseInt(jQuery.browser.version) <= 6) {
		$("head").append('<script language="JavaScript" type="text/javascript" src="/common/script/cookies.js"></script>');
		if ($.cookie('ie-ignore') != 'true') {
			$('body').prepend(
				'<div class="notification-background" id="ie6">' + 
				'<div class="notification">' + 
				'<h1>Did you know that your Internet Explorer is out of date?</h1>' + 
				'<p>To get the best possible experience using our website we recommend that you upgrade to a newer version or other web browser. A list of the most popular web browsers can be found below.</p>' +
				'<ul>' + 
				'<li><a href="JavaScript:window.location=\'http://www.microsoft.com/windows/Internet-explorer/default.aspx\'">' + 
				'<div style="margin: 1px auto; background: transparent url(/images/browser_ie.gif) no-repeat scroll left top; width: 100px; height: 100px;"></div>' + 
				'<div style="margin: 1px auto; color: rgb(128, 128, 128); font-size: 0.8em; height: 18px; line-height: 17px; width: 118px; text-align: center;">Internet Explorer 7+</div>' + 
				'</a></li>' + 
				'<li><a href="JavaScript:window.location=\'http://www.mozilla.com/firefox/\'">' + 
				'<div style="margin: 1px auto; background: transparent url(/images/browser_firefox.gif) no-repeat scroll left top; width: 100px; height: 100px;"></div>' + 
				'<div style="margin: 1px auto; color: rgb(128, 128, 128); font-size: 0.8em; height: 18px; line-height: 17px; width: 118px; text-align: center;">Firefox 3+</div>' + 
				'</a></li>' + 
				'<li><a href="JavaScript:window.location=\'http://www.apple.com/safari/download/\'">' + 
				'<div style="margin: 1px auto; background: transparent url(/images/browser_safari.gif) no-repeat scroll left top; width: 100px; height: 100px;"></div>' + 
				'<div style="margin: 1px auto; color: rgb(128, 128, 128); font-size: 0.8em; height: 18px; line-height: 17px; width: 118px; text-align: center;">Safari 3+</div>' + 
				'</a></li>' + 
				'<li><a href="JavaScript:window.location=\'http://www.opera.com/download/\'">' + 
				'<div style="margin: 1px auto; background: transparent url(/images/browser_opera.gif) no-repeat scroll left top; width: 100px; height: 100px;"></div>' + 
				'<div style="margin: 1px auto; color: rgb(128, 128, 128); font-size: 0.8em; height: 18px; line-height: 17px; width: 118px; text-align: center;">Opera 9.5+</div>' + 
				'</a></li>' + 
				'<li><a href="JavaScript:window.location=\'http://www.google.com/chrome\'">' + 
				'<div style="margin: 1px auto; background: transparent url(/images/browser_chrome.gif) no-repeat scroll left top; width: 100px; height: 100px;"></div>' + 
				'<div style="margin: 1px auto; color: rgb(128, 128, 128); font-size: 0.8em; height: 18px; line-height: 17px; width: 118px; text-align: center;">Chrome 2.0+</div>' + 
				'</a></li>' + 
				'</ul>' + 
				'<p style="clear:both;">If you would like to ignore this message in the future and continue browsing "as-is", <a href="JavaScript:hide(\'ie6\');$.cookie(\'ie-ignore\', \'true\', { path: \'/\', expires: 30 });">please click here (you must accept "cookies" from this website to save these settings)</a></p>' +
				'<p align="right" style="margin:0px;"><a href="JavaScript:hide(\'ie6\');" style="color:#666">[x] Close</a></p>' + 
				'<div>' + 
				'</div>'
			);
		}
	}
});

// Add Style Sheet for IE 7 & 8
jQuery.each(jQuery.browser, function(i, val) {
	if(i=="msie" && val == true && parseInt(jQuery.browser.version) <= 7) {
		$("head").append('<link rel="stylesheet" type="text/css" href="/common/css/ie.css" media="screen" />');
	}
});

// Add Meta Data Based on Page Content
page_title = document.title;
description = $("#main_content p:first").text();

if (description == "") {
	description = "When you change the world of one girl, she changes the world around her. Girl Scouts of Northern California serves over 55,000 girls, helping them develop the skills and knowledge to build better lives for themselves. And that means better, stronger communities for everyone around them. Sure, we still do cookies. But we also do";
}

$("head").append('<meta name="title" content="' + page_title + '" />');
$("head").append('<meta name="description" content="...' + description + '..." />');

// Remove Google Search Watermark on focus
	$("#google_custom_search_0").focus(
		function() {
			$("#google_custom_search_0").removeClass("google_search_img");
		}
	);

// Rollover functionality
	$("ul.dropdown li img").hover(
		function() {
			this.src = this.src.replace("_off","_on");
 		},
 		function() {
			this.src = this.src.replace("_on","_off");
		}
	);
	
// LI Background Rollover functionality
	$("ul.dropdown li").hover(
		function() {
			var background = $(this).css("background-image").replace("_off","_on"); 
			$(this).css({ backgroundImage : background });
 		},
 		function() {
			var background = $(this).css("background-image").replace("_on","_off"); 
			$(this).css({ backgroundImage : background });
		}
	);

// Default Join Selection Functionality
	
	$("div.region_search select[name='region_id']").change(
		function() {
			$.get("/common/ajax/getCity-join.php", { q: this.value },
  				function(data) {
    				
    				$("div.region_search form[name='region']").replaceWith(data);
 					
 					$("div.region_search select[name='city_id']").ready(function(){
						$("div.region_search select[name='city_id']").change(
							function() {
								$(this).parent().submit();
							}
						);
					});
 				
 				});
			
  		}
	);


//
// jQuery Default Functions
// Read up on jQuery at http://docs.jquery.com
//

	roll_over_imgs = new Array(
		"/images/nav_1_about_on.gif",
		"/images/nav_1_activities_on.gif",
		"/images/nav_1_areas_on.gif",
		"/images/nav_1_camp_on.gif",
		"/images/nav_1_product_sales_on.gif",
		"/images/nav_1_shop_on.gif",
		"/images/nav_2_donors_on.png",
		"/images/nav_2_girls_on.png",
		"/images/nav_2_parents_on.png",
		"/images/nav_2_volunteers_on.png",
		"/images/nav_2_alumnae_on.png",
		"/images/loading.gif"
	);

	//for (i = 0; i < roll_over_imgs.length; i++) {
	//	$("<img>").attr("src", roll_over_imgs[i]);
	//}


// jQuery Drop Down Menus
// By Chris Coyier - 2/25/2009
// http://css-tricks.com/simple-jquery-dropdowns/

	$(function(){

		var config = {    
			sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
			interval: 200,  // number = milliseconds for onMouseOver polling interval    
			over: doOpen,   // function = onMouseOver callback (REQUIRED)    
			timeout: 200,   // number = milliseconds delay before onMouseOut    
			out: doClose    // function = onMouseOut callback (REQUIRED)    
		};
    
		function doOpen() {
			$(this).addClass("hover");
			$('ul:first',this).css('visibility', 'visible');
		}
 
		function doClose() {
			$(this).removeClass("hover");
			$('ul:first',this).css('visibility', 'hidden');
		}

		$("ul.dropdown li").hoverIntent(config);
    
		$("ul.dropdown li ul li:has(ul)").find("a:first").append("&nbsp;&nbsp;<img src='/images/nav_pink_arrow.gif' border='0' style='position:relative;top:3px;'>");
		$("ul.dropdown_vert li ul li:has(ul)").find("a:first").prepend("<img src='/images/nav_pink_arrow_left.gif' border='0' style='position:relative;top:3px;'>&nbsp;&nbsp;");

	});

//
//Default Text Functions
//

	$(".defaultText").focus(function(srcc) {
		if ($(this).val() == $(this)[0].title) {
			$(this).removeClass("defaultTextActive");
			$(this).val("");
		}
	});
    
	$(".defaultText").blur(function() {
		if ($(this).val() == "") {
			$(this).addClass("defaultTextActive");
			$(this).val($(this)[0].title);
		}
	});
    
	$(".defaultText").blur();        

//
// Maxlength Form Field Function
//
	
	$(".advMaxLength").keyup(function() {
		maxLength = $(this).attr("maxlength");
		maxLength = Number(maxLength);
		currLength = $(this).val().length;
		if (currLength > maxLength) {
			text = $(this).val().substring(0,maxLength);
			$(this).val(text);
		}
		currLength = $(this).val().length;
		charsLeft = maxLength - currLength;
		$(this).next().text(charsLeft + " Characters Left");
	});

// After everything else has loaded, add the AddThis JavaScript
	$("head").append('<script language="JavaScript" type="text/javascript" src="https://s7.addthis.com/js/200/addthis_widget.js"></script>');


// CMS Reveal Functionality
	$("#cms_tray").hover(
		function() {
			this.src = this.src.replace("_off","_on");
 		},
 		function() {
			this.src = this.src.replace("_on","_off");
		}
	);
	
	$("#cms_tray").toggle(
		function() {
			$("#CMSControl-Login").animate({ 
				top: "5px"
				}, 1500 );	
		},
		function() {
			$("#CMSControl-Login").animate({ 
				top: "-142px"
				}, 1500 );	
		}
	
	);

	$("#cms_tray_tools").hover(
		function() {
			this.src = this.src.replace("_off","_on");
 		},
 		function() {
			this.src = this.src.replace("_on","_off");
		}
	);

	$("img.rollover").hover(
		function() {
			this.src = this.src.replace("_off","_on");
 		},
 		function() {
			this.src = this.src.replace("_on","_off");
		}
	);
	
	$("#cms_tray_tools").toggle(
		function() {
			$("#CMSControl").animate({ 
				top: "-341px"
				}, 1500 );	
		},
		function() {
			$("#CMSControl").animate({ 
				top: "5px"
				}, 1500 );	
		}
	
	);


	//
	// CMS JavaScript Functions
	// Jessica Voytek 06/2009
	//

	function showCMSBlocks() {
		$(".CMS-Content-Block").addClass("CMS-Content-Block-Edit");
		$("#show_cms_blocks").css("display", "none");
		$(".cms-edit, .cms-no-edit, .cms-status-1, .cms-edit-alt, #hide_cms_blocks").css("display", "inline");
		if (!(jQuery().cookie)) {
			$("head").append('<script language="JavaScript" type="text/javascript" src="/common/script/cookies.js"></script>');
		}
		$.cookie("reveal_cms", "true", { path: "/", expires: 30 });	
	}
	
	function hideCMSBlocks() {
		$(".CMS-Content-Block").removeClass("CMS-Content-Block-Edit");
		$(this).attr("value", "Reveal Editable Blocks");
		$(".cms-edit, .cms-no-edit, .cms-status-1, .cms-edit-alt, #hide_cms_blocks").css("display", "none");
		$("#show_cms_blocks").css("display", "inline");
		if (!(jQuery().cookie)) {
			$("head").append('<script language="JavaScript" type="text/javascript" src="/common/script/cookies.js"></script>');
		}
		$.cookie("reveal_cms", "false", { path: "/", expires: 30 });	
	}
		
	$("#show_cms_blocks").click(
		function() {
			showCMSBlocks()
		}
	);
	
	$("#hide_cms_blocks").click(
		function() {
			hideCMSBlocks()
		}
	);

	$(".cms-cancel").click(
		function() {
			$("#hide_cms_blocks").click();
		}
	);
	
	
/*!
 * liScroll 1.0
 * Examples and documentation at: 
 * http://www.gcmingati.net/wordpress/wp-content/lab/jquery/newsticker/jq-liscroll/scrollanimate.html
 * 2007-2009 Gian Carlo Mingati
 * Version: 1.0.1 (07-DECEMBER-2009)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * Requires:
 * jQuery v1.2.x or later
 * 
 */
 

jQuery.fn.liScroll = function(settings) {
	settings = jQuery.extend({
	travelocity: 0.07
	}, settings);
	return this.each(function(){
	var $strip = jQuery(this);
	$strip.addClass("newsticker")
	var stripWidth = 0;
	var $mask = $strip.wrap("<div class='mask'></div>");
	var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");
	var containerWidth = $strip.parent().parent().width(); //a.k.a. 'mask' width
	$strip.find("li").each(function(i){
	stripWidth += jQuery(this, i).width();
	});
	$strip.width(stripWidth);
	var totalTravel = stripWidth+containerWidth;
	var defTiming = totalTravel/settings.travelocity; // thanks to Scott Waye
	function scrollnews(spazio, tempo){
	$strip.animate({left: '-='+ spazio}, tempo, "linear", function(){$strip.css("left", containerWidth); scrollnews(totalTravel, defTiming);});
	}
	scrollnews(totalTravel, defTiming);
	$strip.hover(function(){
	jQuery(this).stop();
	},
	function(){
	var offset = jQuery(this).offset();
	var residualSpace = offset.left + stripWidth;
	var residualTime = residualSpace/settings.travelocity;
	scrollnews(residualSpace, residualTime);
	});
	});
};

	$(function(){ 
    	$("ul#hometicker").liScroll();
    }); 
	
});



