﻿// Gets QueryString Parameter
function getParameterByName( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return null;
  else
    return decodeURIComponent(results[1].replace(/\+/g, " "));
}

$(document).ready(function(){
	// Begin PageRedirect Meta Data
	var link = $("meta[name=PageRedirect]").attr("content");
	if (link != null) {
		if (link.indexOf("http") != 0) {
			link = "http://" + link;
		}
		window.location = link;
	}
	// End PageRedirect Meta Data
		
	// Begin Search Setup
	var searchUri = "/roc/search.aspx?type=web&q=";
	
	// Disable all enter key submissions by default
	$('input').keypress(function (e) {
		var code = null;
		code = (e.keyCode ? e.keyCode : e.which);
		return (code == 13) ? false : true;
    });
	
	// Clear search input on focus
	$("li.search > .searchField").focus(function(){
		$(this).val("");
	});		
	
	// Simulates Enter Key Press Submission
	$("li.search > .searchField").keyup(function(e){
		var code = null;
		code = (e.keyCode ? e.keyCode : e.which);
		if (code == '13')
		{
			e.preventDefault();
			window.location =  searchUri + $(this).val();
			return false;
		}
	});	
	
	$("li.search > .btnSiteSearch").click(function(e){		
		e.preventDefault();
		window.location = searchUri + $("li.search > .searchField").val();
		return false;
	});	
	
	// End Search Setup
	
	// Begin Search Issues Callout
	//Clear Default Input Text
	$("#txt_SearchWord").focus(function(){
		$("#txt_SearchWord").val("");
	});
	
	// Simulates Enter Key Press Submission
	$("#txt_SearchWord").keyup(function(e){
		var code = null;
		code = (e.keyCode ? e.keyCode : e.which);
		if (code == '13')
		{
			e.preventDefault();
			var searchIssueUri = searchUri.replace("type=web&q=","type=legislativeissue");
			var searchIssueParameters = "";

			searchIssueParameters += "&issue_date=" + $("#ddl_SearchDate").val();
			searchIssueParameters += "&issue_type=" + $("#ddl_SearchLocation").val();
			searchIssueParameters += "&q="
			if ( $("#txt_SearchWord").val() != "" && $("#txt_SearchWord").val() != "Search by keyword")
			{
				searchIssueParameters += $("#txt_SearchWord").val();
			}

			window.location =  searchIssueUri + searchIssueParameters;
			return false;
		}
	});

	
	$(".btn_SearchIssues").click(function(e){
		e.preventDefault();
		var searchIssueUri = searchUri.replace("type=web&q=","type=legislativeissue");
		var searchIssueParameters = "";

		searchIssueParameters += "&issue_date=" + $("#ddl_SearchDate").val();
		searchIssueParameters += "&issue_type=" + $("#ddl_SearchLocation").val();
		searchIssueParameters += "&q="
		if ( $("#txt_SearchWord").val() != "" && $("#txt_SearchWord").val() != "Search by keyword")
		{
			searchIssueParameters += $("#txt_SearchWord").val();
		}

		window.location =  searchIssueUri + searchIssueParameters;
		return false;
	});
	// End Search Issues Callout
	
	var textFromBox = $("input").val();
	
	function removeSubNav(){
		$(".submenu").hover(function(){
		 }, function(){
			 //$(this).hide();
			 $(this).html("");			 			 
		});
	}
function orginalMenuFunction(){	
	$("#navigation li").hover(function(){
		//$(".submenu").hide();									   
		$(".hover").removeClass("hover");
		var submenuItems = $(this).children(".submenuItems").html();
		if(submenuItems != null){
			//alert(submenuItems);
			$(".submenu").show();
			$(".submenu").html(submenuItems);
			$(this).addClass("hover");
			//removeSubNav();
		}					 
	});
}

orginalMenuFunction();

	 var linksForMenu = $(".ekflexmenu_button_selected").parent("li").children(".submenuItems").html();
	 //alert(linksForMenu);
		if(linksForMenu != null){
      //alert(submenuItems);
      $(".submenu").show();
      $(".submenu").html(linksForMenu);
      $(this).addClass("hover");
      //new hotness
    $(".submenu").hover(function(event){
      event.preventDefault();
    }, function(){
      //$(this).hide();
      $(this).html(linksForMenu);			 			 
    });  
    
    $("#navigation").hover(function(event){
      event.preventDefault();
    }, function(){
      //$(this).hide();
      $(".submenu").html(linksForMenu);			 			 
    });   
      //end new hotness
      //orginalMenuFunction();
		}	

	$("#navigation ul li:last-child").addClass("last");
	$(".floatRight li:last-child").addClass("last");
	// Navigation
	if ($("#about").length) {  
	$(".submenu , .ekflexmenu_button_selected").addClass("aboutbg");
  $(".submenuContainer").addClass("aboutbg");
	$("#navigation").addClass("purple");
	}
	if ($("#about").length) {  
		  $(".redInt").addClass("purpleInt");
	}
	if ($("#ls").length) {  
		 $(".submenu").addClass("lsbg");
		 $(".submenuContainer").addClass("lsbg");
		 $("#navigation").addClass("redish");
	}
	if ($("#ls").length) {  
		$(".redInt").addClass("redInt");
	}
	if ($("#gi").length) {  
		$(".submenu").addClass("gibg");
		$(".submenuContainer").addClass("gibg");
		$("#navigation").addClass("orange");
	}
	if ($("#gi").length) {  
		$(".redInt").addClass("orangeInt");
	}
	if ($("#ne").length) {  
		$(".submenu").addClass("nebg");
		$(".submenuContainer").addClass("nebg");
		$("#navigation").addClass("blue");
	}
	if ($("#ne").length) {  
		$(".redInt").addClass("blueInt");
	}
	if ($("#rl").length) {  
		$(".submenu").addClass("rlbg");
		$(".submenuContainer").addClass("rlbg");
		$("#navigation").addClass("green");
	}
	if ($("#rl").length) {  
		$(".redInt").addClass("greenInt");
}

// Homepage News Rotator
$('.homerotation').vTicker({
    speed: 500,
    pause: 4000,
    animation: 'fade',
    mousePause: true,
    showItems: 1
});
});

// Begin AutoFlowplayer
$(document).ready(function () {
	AutoFlowplayer();
});

// Set to Server Flowplayer SWF path
var flowplayerSwfPath = "/js/flowplayer/flowplayer-3.2.5.swf";

// Edit With Caution!
// Loops through all Anchor tags with "flowplayer" CssClass
function AutoFlowplayer() {
	var regExpressions = ["width=([0-9]{1,4}(px)?)", "height=([0-9]{1,4}(px)?)"];            
	var errorMessage = "AutoFlowplayer Error: {0}";
	var errorHtmlFormat = "<span style='color: red;'>{0}</span>";

	$("a.flowplayer").each(function (i) {
		try {
			var file = String($(this).attr("href"));
			var style = "";

			if (file.indexOf("width=") > -1 && file.indexOf("height=") > -1) {
				var width = String(file.match(regExpressions[0])[1]);
				width = (width.indexOf("px") == -1) ? width + "px" : width; // Adds px if not present

				var height = file.match(regExpressions[1])[1];
				height = (height.indexOf("px") == -1) ? height + "px" : height; // Adds px if not present

				style = "display:block;width:" + width + ";height:" + height + ";";
			}

			// Correct URL Parameters for Flash
			file = file.replace("&amp;", "&").replace("&", "%26");
			$(this).attr("href", file);

			// update ID
			var id = ($(this).attr("id") == "" || $(this).attr("id") == null) ? "AutoFlowplayer_" + i : $(this).attr("id");
			$(this).attr("id", id);

			// set style
			style = ($(this).attr("style") == undefined) ? style : $(this).attr("style");
			$(this).attr("style", style);

			// flowplayer the ID
			if (typeof flowplayer == "function" && style != "") {
				// Strip Subitems if no splash image is found
				if (!$(this+":contains('<img')")){
					$(this).html("");
				}
				flowplayer(id, flowplayerSwfPath);
			}
			else if (typeof flowplayer != "function") {
				throw (errorMessage.replace("{0}", "Flowplayer could not be found."));
			}
			else if (style == "") {
				throw (errorMessage.replace("{0}", "Width and Height could not be determined from HREF URL parameters for the file " + file));
			}
		} catch (err) {
			alert(err);
			$("#" + id).html(errorHtmlFormat.replace("{0}", err));
		}
	});
}
