$(document).ready(function(){
	if(window.location.href.indexOf("digital-media-and-software.aspx?sd=1") != -1){
		tb_show("Digital Mediat Incentive Demo", "/opportunities/key-industries/digital-media-incentive-demo.aspx?sp=/opportunities/key-industries/digital-media.aspx&KeepThis=true&TB_iframe=true&height=530&width=815&modal=true", null);
	}
	
	if(window.location.href.indexOf("la-economic-quarterly.aspx?src=hp_stat&so=1") != -1 || window.location.href.indexOf("la-economic-quarterly.aspx?so=1") != -1){
		tb_show("EQ Overlay", "/news--multimedia/la-economic-quarterly/eq-overlay.aspx?KeepThis=true&TB_iframe=true&height=600&width=950&modal=true", null);
	}
	
	// show additional resources overlay on any page with arid=xx
	var ar_id = $.jqURL.get('arid');
	if(ar_id){
		tb_show("Additional Resources Overlay", "/additional-resources/multimedia-display.aspx?id="+ar_id+"&KeepThis=true&TB_iframe=true&height=530&width=750&modal=true", null);
	}
	
	$(".child_node").hide();
	$(".child_node:first").show(); // show the first one on page load
	
	$("#child_node_selector li a").click(function(e){
		e.preventDefault();
		
		$("#child_node_selector li").removeClass("selected");
		$(this).parent().addClass("selected");
		
		var child = "#" + $(this).attr("rel");
		
		$(".child_node").hide();
		$(child).fadeIn("300");
	});
	
	
	// new industry pages
	if ($('#cycle').cycle != undefined) {
		$('#cycle').cycle({
			fx: 'scrollHorz',
			timeout:   10000,
			speed: 700,
			pager: '#cycle_nav',
			easing:  'easeInOutQuad',
			cleartypeNoBg: true
		});
	}
	
	
	if ($('.cycle_video_plus').rotate != undefined) {
		$('.cycle_video_plus').rotate({angle:0});
	}
	

	$('a.cycle_video_btn').hover(
		function() {
			$(this).find('.cycle_video_plus').rotateAnimation(360);
		},
		function() {
			$(this).find('.cycle_video_plus').rotateAnimation(-0);
		}
	);
	
	// these need to go in site-wide js to replace clunky inline js
	$('#topnav_faststart').hover(
		function() {
			$(this).css('background-color', '#006993');
			$('#topnav_faststart a').css('color', '#ffffff');
		},
		function() {
			$(this).css('background-color', '#ffffff');
			$('#topnav_faststart a').css('color', '#006993');
		}
	);
	
	$('#universal_misc div').hover(
		function() {
			$(this).css('background-color', '#006993');
			$('#universal_misc div[id=' + this.id + '] a').css('color', '#ffffff');
		},
		function() {
			$(this).css('background-color', '#ffffff');
			$('#universal_misc div[id=' + this.id + '] a').css('color', '#3c3c3c');
		}
	);
	
	
	// this needs to be added to site-wide
	$('#opportunities li a').click(function(){
		
		//currSection = this.id;
		
		$('#opportunities li a[id!=' + this.id + ']').removeClass('active').animate({ marginTop: '6px', marginBottom: '6px', paddingTop: '6px', paddingBottom: '6px' }, 100);
		$(this).addClass('active');
		
		
		numbersActive = false;
	});
	
});



/*	///////////////
	GLOBAL FUNCTION returns query param value, takes param name as argument
///////////////////*/

function gqp( name ){  
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
	var regexS = "[\\?&]"+name+"=([^&#]*)";  
	var regex = new RegExp( regexS );  
	var results = regex.exec( window.location.href );  
	if( results == null )    
		return "";  
	else    
		return results[1];
}

/*	///////////////
	GLOBAL SEARCH FUNCS
///////////////////*/

function searchSite(){
	var kw = document.getElementById('txtKeyword').value;
	if(kw == "" || kw == "Search LED Site" || kw == "search led site") {
		return false;	
	}
	
	return true;
}

function clearMe(obj){
	var val = obj.value;
	if(val == "Search LED Site"){obj.value = "";}
}



/*	///////////////
	TARGET logic
///////////////////*/


 //google analytics - custom segment tracking
function tellGoogle(targ_sel){
	
	var currCkieVal = $.cookie('led_target');
	
	//check to be sure that a valid, new target is selected
	if(targ_sel != "target_d" && currCkieVal != targ_sel){
		if(targ_sel == "target_a"){
			pageTracker._setVar('Expansion/Relocation');
		} else if(targ_sel == "target_b"){
			pageTracker._setVar('Small Businesses');
		} else if(targ_sel == "target_c"){
			pageTracker._setVar('In-State Companies');
		}
		
		if(pgName == "homepage.aspx" && strURL != "http://dev.ledlouisiana.com/" && strURL != "http://staging.ledlouisiana.com/"){
			//Send Google Website Optimizer conversion
			sendConversion();
		}
	}
}


//resets the value of 'led_target'
function setTarget(targ_sel){
	
	//Send Google Target Change param
	tellGoogle(targ_sel);

	//if in the default state, set target to a
	if(targ_sel == "target_d"){
		targ_sel = "target_a";
	}
	
	//get url
	var strURL = document.location.href
	
	if(strURL.indexOf("http://dev.ledlouisiana.com/") != -1 || strURL.indexOf("http://staging.ledlouisiana.com/") != -1){
		// dev or staging
		$.cookie('led_target', targ_sel, { expires: 365, path: '/', domain: 'ledlouisiana.com' });
	} else {
		// live site
		$.cookie('led_target', targ_sel, { expires: 365, path: '/', domain: 'louisianaeconomicdevelopment.com' });
	}
}

//get the value of the query param 'gt'
var tgURL = $.jqURL.get('gt');

if(tgURL == undefined || tgURL == ""){
	//get the value of the query param 'gt'
	tgURL = gqp('gt');
}

//if 'tg' exists and is one of the approved values, set a cookie
if(tgURL != null && (tgURL == 'a' || tgURL == 'b' || tgURL == 'c')){
    var tgCkie = 'target_' + tgURL;
    setTarget(tgCkie);
} 

//if the cookie has still not been defined, set it = to default
if($.cookie('led_target') == null){
	setTarget('target_d');
}

// !if the page title prefix changes, the start position should change here!
//clean up the page title - remove the prefix, get the value
//var pgTitle = document.title.substring(32,document.title.length).toLowerCase();

//get url
var strURL = document.location.href
//get page name + extension
var pgName = strURL.match(/\w+\.aspx/)

//if no aspx page exists, set pgName eq to home
if(strURL.match('http://www.louisianaeconomicdevelopment.com/opportunities/?') != null || strURL.match('http://dev.ledlouisiana.com/opportunities/?') != null || strURL.match('http://staging.ledlouisiana.com/opportunities/?') != null){
	pgName = "opportunities.aspx";
} else if((strURL == "http://www.louisianaeconomicdevelopment.com/" || strURL.match('http://www.louisianaeconomicdevelopment.com/?') != null || strURL == "http://dev.ledlouisiana.com/" || strURL.match('http://dev.ledlouisiana.com/?') != null || strURL == "http://staging.ledlouisiana.com/" || strURL.match('http://staging.ledlouisiana.com/?') != null) && pgName == null){
   pgName = "homepage.aspx";
} 



//get cookie value if on the homepage or the opportunities section
var tgCkie = $.cookie('led_target');

//otherwise, keep nav deselected
if (strURL.match('/opportunities') == null && pgName != "homepage.aspx" && pgName != "homepage_t3.aspx"){
	//tgCkie = "";
}


/*/////////
	ECONOMIC QUARTERLY EDITION SELECTION
*/////////

function openDownload(downloadName){
	if(downloadName != "" && downloadName != "- Select Issue -"){
		pageTracker._trackPageview('/downloads/' + downloadName);
		window.open('http://www.louisianaeconomicdevelopment.com/downloads/' + downloadName);
	}
}
