// JavaScript Document
$(document).ready(function() {	

	//Show Banner
	$(".main_image .desc").show(); //Show Banner
	$(".main_image .block").animate({ opacity: 0.95 }, 1 ); //Set Opacity

	//Click and Hover events for thumbnail list
	$(".image_thumb ul li:first").addClass('active'); 
	$(".image_thumb ul li").click(function(){ 
		//Set Variables
		var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image
		var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL
		var imgDesc = $(this).find('.block').html(); 	//Get HTML of block
		var imgDescHeight = $(".main_image").find('.block').height();	//Calculate height of block	
		
		if ($(this).is(".active")) {  //If it's already active, then...
			return false; // Don't click through
		} else {
			//Animate the Teaser		
			$(".main_image img").animate({ opacity: 0}, 250 );
			$(".main_image .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 250 , function() {
				$(".main_image .block").html(imgDesc).animate({ opacity: 0.95,	marginBottom: "0" }, 250 );
				$(".main_image img").attr({ src: imgTitle , alt: imgAlt}).animate({ opacity: 1}, 250 );
			});
		}
		
		$(".image_thumb ul li").removeClass('active'); //Remove class of 'active' on all lists
		$(this).addClass('active');  //add class of 'active' on this list only
		return false;
		
	}) .hover(function(){
		$(this).addClass('hover');
		}, function() {
		$(this).removeClass('hover');
	});
			
	//Toggle Teaser
	$("a.collapse").click(function(){
		$(".main_image .block").slideToggle();
		$("a.collapse").toggleClass("show");
		return false;
	});
	
});//Close Function


$(document).ready(function() {	

$('area').click(function() { 
    var url = $(this).attr('href'); 
    var coords = $(this).attr('coords').split(','); 
	var district = $(this).attr('alt').split(',');
    // Your code here 

	$("#boards").load("/page_inc/getboards.cfm", {board: district[0], district: district[1]}, function(){
		});
	


	// To prevent default action 
  return false; 
});

});//Close Function

$(function() {
			$('.corpmembers').cycle({
				fx: 'fade',
				delay: -2000,
				speed: 600,
				next:   '#next', 
    			prev:   '#prev',
				pause:	1,
				random: 'true'
			});
			
			$('#homeaccord, #council_accordion, #assoc_accordion').accordion({ 
				active: false, 
				header: '.title',
				autoheight: false,
				alwaysOpen: false,
				selectedClass: 'current'
			});
			
			
			$(".board_lb").colorbox({width:"700px", height:"550px", iframe:true});
			$(".iframe").colorbox({width:"640px", height:"550px", iframe:true});
			$(".youtube").colorbox({innerWidth:560, innerHeight:340, iframe:true});
			$('.signup').colorbox({width:"300px", height:"500px", iframe:true});
			$('.weather').colorbox({width:"700px", height:"730px", iframe:true});
			$('.markets').colorbox({width:"350px", height:"450px", iframe:true});
		
			$(".more_1").colorbox({width:"640px", inline:true, href:"#messagePOP1"});
			$(".addRep").colorbox({width:"640px", height:"500px", inline:true, href:"#addRep"});
			$(".lightbox").colorbox();
			$(".chart").colorbox();
			$(".list").colorbox({width:"610px", height:"550px", iframe:true});
			
						initPage();


				
});		

function resetboard(board){

	$("#boards").load("/page_inc/getboards.cfm", {board: board});
	
	// To prevent default action 
  return false; 
};
	

function openME(img) {
	
			$.fn.colorbox({open:true, href:img}); 

}

function popMessage(mi){

			$.fn.colorbox({open:true, width:"640px", inline:true, href:"#messagePOP_"+mi}); 

		
}

$(function() { 
					
					$("div.hometabs").tabs(".homeimages > div", { 
 
						// enable "crosfade" effect 
						effect: 'fade', 
				 		clickable: false,
				 		
						// start from the beginning after the last tab 
						rotate: true 
				 
					// use the slideshow plugin. It accepts its own configuration 
					}).slideshow({autoplay: true, interval: 10000});
				});


$(function() {


var root = $("#wizard").scrollable({size: 1, clickable: false});



// some variables that we need
var api = root.scrollable(), drawer = $("#drawer");

// validation logic is done inside the onBeforeSeek callback
api.onBeforeSeek(function(event, i) {

	// we are going 1 step backwards so no need for validation
	if (api.getIndex() < i) {

		// 1. get current page
		var page = root.find(".page").eq(api.getIndex()),

			 // 2. .. and all required fields inside the page
			 inputs = page.find(".required :input").removeClass("error"),

			 // 3. .. which are empty
			 empty = inputs.filter(function() {
				return $(this).val().replace(/\s*/g, '') == '';
			 });

		 // if there are empty fields, then
		if (empty.length) {

			// slide down the drawer
			drawer.slideDown(function()  {

				// colored flash effect
				drawer.css("backgroundColor", "#bbb");
				setTimeout(function() { drawer.css("backgroundColor", "#eee"); }, 1000);
			});

			// add a CSS class name "error" for empty & required fields
			empty.addClass("error");

			// cancel seeking of the scrollable by returning false
			return false;

		// everything is good
		} else {

		$("#vname").html($("#prefix").val() + " " + $("#fname").val() + " " + $("#lname").val());
		$("#vemail").html($("#email").val());
		$("#vaddress").html($("#address").val() + "<br>" + $("#city").val() + ", " + $("#state").val() + " " + $("#zip").val());				
		$("#vphone").html($("#phone").val());
		$("#vsubject").html($("#subject").val());
		

		
		
		$("#message2").text($("#message").val());
		
		
	var strMultiLineText = $("#message2").html();
	
    var strSingleLineText = strMultiLineText.replace(

     new RegExp( "\\n", "g" ),
	      
     "<br>"
     );
      
	  
    
    
	$("#message2").html(strSingleLineText);
                     
		 

			// hide the drawer
			drawer.slideUp();
		}

	}

	// update status bar
	$("#status li").removeClass("active").eq(i).addClass("active");

});



// if tab is pressed on the next button seek to next page
root.find("button.next").keydown(function(e) {
	if (e.keyCode == 9) {

		
		// seeks to next tab by executing our validation routine
		api.next();
		e.preventDefault();
		
	}
});

});
function addText(mID) {
	

	$("#message").val($("#message").val() + "\r\r" + $("#messagePOP_"+mID).text());

	return false;
};

function clearText() {
	$('#message').val("");
	
		return false;
};


function initPage(){

var foo;

$("#districts").change(function(){
		foo = $('#districts').val();
		
		$("#reps").load("/page_inc/reps.cfm", {action: 'getReps', district: foo}, function(){
			initPage();
 });
								});
};






function addREP(rep, repID, repemail){
	
	var valcheck;
	
	valcheck = $('#rep_'+repID).attr('checked'); 
	

	if(valcheck == true){
		$("#replist").html($("#replist").html() + "<li id='newrep_"+repID+"'><span style='float:left'>"+rep+"</span><div id ='remRep' onclick='return removeRep("+repID+");' style = 'cursor:pointer; float:left; margin-left:5px; display:block; font-size:10px; color:#000; text-decoration:underline'>remove</div><div style='clear:left'></div></li>" );
		$("#hiddenreps").html($("#hiddenreps").html() + "<input type='hidden' name='contacts' id='newrep_"+repID+"' value='"+repemail+"'>" );
	}else{
		$("#newrep_"+repID).remove();
		$("#newrep_"+repID).remove();
	};

};

function removeRep(repID){
		$("#newrep_"+repID).remove();
		$("#newrep_"+repID).remove();

};
