/*-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  Hand crafted by Andrew Pougher  - (c)2010 e3msi.com / andrewpougher.co.uk  watermarked code
This work may not be taken for any project other than ChildServ
-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/

$(document).ready(function() {


// side graphic
$("#leftnav").append("<img src='http://www.childserv.org/img/corner_L.gif' alt='childserv'>")



/*==============================
load ads onready
===================================*/

var panelID = $("#panelID").text()
getPanel(panelID)

/*-----------------
  window width
------------------*/

 $(window).resize(function(){
        var h = $(window).height();
        var w = $(window).width();
		if (w < parseInt(1160)){
        $(".sharepost").fadeOut(300);
	}else{
	$(".sharepost").fadeIn(300);
	}
    });




/*-----------------
Brand Fun
------------------*/	


	$("#brand a").hover(function() {
    $(this).html("<small>Helping Chicagoland's At-Risk Children and Their Families Build, Achieve, and Sustain Better Lives.</small>");
   $(this).css({"background-image":"url(http://www.childserv.org/img/brand-over.png)", "text-indent": "-9999px", "fontSize": "2px" });
			}, function() {
    		$(this).css({"background-image":"url(http://www.childserv.org/img/brand.png)", "text-indent": "-9999px"});
	});


/*-----------------
Poogeroo menu v1.2
------------------*/
   $(".dropdown li").hover(function(){
        $(this).addClass("hover");
        $('ul:first',this).css('visibility', 'visible');
    }, function(){
   $(this).removeClass("hover");
   $('ul:first',this).css('visibility', 'hidden');
});
$(".dropdown li ul").find("a").prepend(" &raquo; ");



/* =============================
picture slide
================================*/
	// news rotator for front page.
	$('#slides').cycle({ 
		//fx:     'scrollLeft', 
		//fx:     'turnDown', 
		//fx:     'zoom', 
		//fx:      'scrollDown', 
		//timeout: 5000, 
		delay:  -2000, 
		//easing: 'bounceout',
		//easing:  'backinout',
		fx:    'fade',
    		speed:    300, 
    		timeout:  5000
		//sync:   0, 
		//delay: -2000 
	});



/*=========================
    menu
========================*/

/* --------------------------------------------------
  Gather little Children Menu
----------------------------------------------------*/
$(".plist li").each(function() {
var p = $(this).attr("value")
var whichLI= $(this)
$.ajax({ 
	url: "aj_getMenuChildren.aspx?c=" + p, 
	dataType: "html", 
	type: "GET", 
	beforeSend: function(){
	},
	error: function(){ 
	$(whichLI).css("color","red")
	}, 
	success: function(data){
	$(whichLI).after(data)
	}
	}); 
});


/* --------------------------------------------------
  Left Minor Nav
----------------------------------------------------*/
$(".plist li").hover( function(){
var linkNum = $(this).attr("value")
     $('li.'+linkNum).slideDown('fast').show();
   
 $(this).parent().hover(function() {  
        }, function(){  
            $(this).parent().find('li.'+linkNum).slideUp('fast'); 
        });
});



document.getElementById('page_title').text = "Childserv.org - " + $('h2:first').text()

/* -------------------
 Accesibility
-----------------------*/

	$('#footer .btn').click(function(){
	var ourText = $('#middleCol');
	var currLineH = ourText.css('line-height');
	var currFontSize = ourText.css('fontSize');
	var LinePX = currFontSize.slice(-2);
	var finalNum = parseFloat(currFontSize, 10);
	var finalLine = parseFloat(currLineH, 22);
	var stringEnding = currFontSize.slice(-2);
	if(this.id == 'large') {
				finalNum *= 1.2;
				finalLine *= 1.2;
			}
			else if (this.id == 'small'){
				finalNum /=1.2;
				finalLine /=1.2;
			}
			ourText.css({'fontSize': finalNum + stringEnding, 'line-height': finalLine + stringEnding });
		});

/* -------------------
 E-News
-----------------------*/

$("a.enews").fancybox({
	'autoDimensions' : false,
	'overlayOpacity' : 0.75, 
	'width'	: 550,
	'height': 250,
	'padding' : 10,
	'margin' : 0,
	'scrolling': 'no',
	'titleShow': false,
	'onClosed': function() {
	$("#reg_error").hide();
	}
});

$('#enewsletter input').bind('keypress', function(e) {
	if(e.keyCode==13){
	runRegister();
	return false;
	}
	});

$("#registerbtn").click( function() {
	runRegister();
	});

/* -------------------
 SEARCH
-----------------------*/

$('#search input').bind('keypress', function(e) {
	if(e.keyCode==13){
	runSearch();
	return false;
	}
	});


$("a#searchsite").fancybox({
'autoDimensions' : false, 
	'width'	: 550,
	'height': 180,
	'padding' : 0,
	'margin' : 0,
	'scrolling': 'no',
	'titleShow': false,
	'onStart':  function() {
	$("#sch").focus();
	},
	'onClosed': function() {
	$("#rem_error").hide();
	}
});

$(".searchit").click( function() {
	runSearch();
	});



});  // END

/* -------------------
 Register Fn
-----------------------*/

function runRegister(){
	the_job = $('#enewsletter input:radio:checked').val();
	the_fname = $('#enewsletter #nwsfName').val();
	the_lname = $('#enewsletter #nwslName').val();
	the_email = $('#enewsletter  #nwsEm').val();
	var newsdata = ("fn=" + the_fname  + "&ln=" + the_lname + "&jb=" + the_job + "&em=" + the_email);
	if (the_fname !=0 && the_lname !=0  && isValidEmailAddress(the_email)) {
$.fancybox.showActivity();
alert(newsdata)
	$.ajax({
		type	: "GET",
		cache	: false,
		url	: "aj_joinenews.aspx",
		data	: newsdata,
	error: function(){ 
		$.fancybox("Cannot Register you right now, Try Later.");
	}, 
		success: function(data) {
			$.fancybox(data);
			$.fancybox.resize();
		}
	});
	}else{
	$("#reg_error").fadeIn( function(){
	setTimeout( function() { $("#reg_error").fadeOut("fast"); }, 2000);
	});
	return false;
	}
}


/* -------------------
 SEARCH fn
-----------------------*/
function runSearch(){

	if ($("#sch").val().length < 2 ) {
	       $("#rem_error").fadeIn( function(){
     		setTimeout( function() { $("#rem_error").fadeOut("fast"); }, 2000);
   		});
 return false;
	}
	$.fancybox.showActivity();
	var nt = $("#sch").val()
	var searchdata = ("s=" + nt)
//alert(searchdata)
	$.ajax({
		type	: "GET",
		cache	: false,
		url	: "aj_search.aspx",
		data	: searchdata,
		success: function(data) {
			$.fancybox(data);
			$.fancybox.resize();
		}
	});

}


/* -------------------
 Panel getter fn
-----------------------*/

	function getPanel(pnl){
$.ajax({ 
	url: "aj_getpanel.aspx?pnl=" + pnl, 
	dataType: "html", 
	type: "GET", 
	beforeSend: function(){
	$('#showpanel').html("<img src='img/loading.gif'/>");
	},
	error: function(data){ 
	$("#showpanel").html('Panels cannot be retrieved right now' + data); 
	$("#showpanel").fadeIn(350)
	}, 
	success: function(data){
	$('#showpanel').html(data)
	$("#showpanel").fadeIn(350)
	//--cufon must come after
	Cufon.replace('h1, .pullquote p', { fontFamily: 'bubbleboddy Light' });

	} 
	}); 
}

/* -----------------------------------
	choose menu item Highlight
-------------------------------------*/
function setMenuhighlight(){
var thepid = parseInt($('#pageID').text())
$(".plist li").each(function(n) {
 	var $li = $(this)
        name = parseInt($li.attr('name'))
	if ( name == thepid){ 
		$li.addClass('thispage');
		if($($li).hasClass("child")){
			$li.attr("style","font-size:14px;padding-bottom:3px;font-weight: bold;"); // STYLE THE SUB SELECTION
			 $($li).slideDown('fast'); // SHOW THE SELECTION
		}
		// $("#hd_NavName").val($(this).find("a").text())
		}
      }); 
}


/*--------- FUNCTIONS --------------*/

function fbs_click(){
u=location.href;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;
}
