
function popitup(url, w, h) {
	var p_args = 'height='+h+',width='+w+',scrollbars=1';
	newwindow=window.open(url,'name',p_args);
	if (window.focus) {newwindow.focus()}
	return false;
}


function showMovingForm(id) {
		
		if (document.getElementById) { 
			document.getElementById(id).style.display = 'block';
		}
			else {
				
				if (document.layers) { 
					document.id.display = 'block';
				}
				
				else {
					document.all.id.style.display = 'block';
				}
		}
		
}

function hideMovingForm(id) {
		
		if (document.getElementById) { 
			document.getElementById(id).style.display = 'none';
		}
			else {
				
				if (document.layers) { 
					document.id.display = 'none';
				}
				
				else {
					document.all.id.style.display = 'none';
				}
		}
		
}


    /////////////////////////////////////////////////////////
    //// SHOW / HIDE SUB MENUS //////////////////////////////
    /////////////////////////////////////////////////////////
	var rows = new Array('row1', 'row2', 'row4');
	var switched = false;
	
	function collapseRow(id)
	{
		if (document.getElementById)
		{ // DOM3 = IE5, NS6
			
			document.getElementById(id).style.display = 'none';
						
		}
		else {
				if (document.layers)
				{ // Netscape 4
					document.id.display = 'none';
				}
				else
				{ // IE 4
					document.all.id.style.display = 'none';
				}
		}
		
	}
	
	///////////////////////////
	function collapseRows()
	{
		for(var i=0; i<rows.length; i++)
		{
			collapseRow(rows[i]);
		}
	}
	
	function switchRow(rowid) {
	

		var rowid;
		if(row = document.getElementById(rowid))
		{
			if(row.style.display == 'block') {
				row.style.display = 'none';
			}
			else {
				collapseRows();
				row.style.display = 'block';
			}
		}

	}
	
	
	//////////////////////////////
	//switch main navigation tab//
	//////////////////////////////
	jQuery.noConflict();
	jQuery(document).ready(function() {
		
		jQuery("#navigation ul li").hover(
			function(){ jQuery(this).children(".nav_link").toggleClass("dHover"); jQuery(this).children(".menu_drop").show(); },
			function(){ jQuery(this).children(".nav_link").toggleClass("dHover"); jQuery(this).children(".menu_drop").hide(); }
		);
		
	
	    jQuery("#navigation ul li").removeClass("current");
	    
	    if(location.href.indexOf("whyenergia/") != -1 )
	    {
	       jQuery("#navigation ul li#why").addClass("current");
	    }
	    
	    if(location.href.indexOf("supply/") != -1 )
	    {
	       jQuery("#navigation ul li#electricity").addClass("current");
	    }
	    
	    if(location.href.indexOf("gas/") != -1 )
	    {
	       jQuery("#navigation ul li#gas").addClass("current");
	    }
	    
	    if(location.href.indexOf("energyefficiency/") != -1 )
	    {
	       jQuery("#navigation ul li#efficiency").addClass("current");
	    }
	    
	    if(location.href.indexOf("customerservice/") != -1 )
	    {
	       jQuery("#navigation ul li#customer").addClass("current");
	    }
	    
	    if(location.href.indexOf("news/") != -1 )
	    {
	       jQuery("#navigation ul li#news").addClass("current");
	    }
		
		
		//Home page slide show
		if (jQuery("#home-promo").length) {
			//console.log("In here ...");
			jQuery(".fadein img:gt(0)").hide();
			setInterval(function(){jQuery('.fadein :first-child').fadeOut('slow').next('img').fadeIn('slow').end().appendTo('.fadein');}, 5000);
		}
		
		if (jQuery("#openVideo").length) {
			jQuery("#openVideo").click(function(){
				openVideoInPopUp();
				return false;
			});
		}
		
		
		
		if (jQuery("input.filter").length) {
			jQuery("input.filter").focus(function(){jQuery(this).attr('value','')});
		}
		
		//Windfarm location list filter functionality
		if (jQuery("ol.live_filter").length) {
			//cancel form submission on enter key press
			jQuery("#aspnetForm").bind( "keypress", function(e) {if (e.keyCode == 13) return false;} );
			//console.log('ol.live_filter');
			jQuery('ol.live_filter').liveFilter('basic');
			
			jQuery('#refresh').click(function(){ window.location.reload(); return false; });
		}
		
});
	
/* Function to open YouTube video of Energia TV commercial */
openVideoInPopUp = function() {
	
	var scroll = (document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
	
	var embed;
	
	//Test for HTML5 video support
	if (Modernizr.video) {	
			//console.log("Video is supported");
			embed = '<iframe width="700" height="393" src="http://www.youtube.com/embed/dvVAtdtOTeI" frameborder="0" allowfullscreen></iframe>';
	} else {
			//console.log("Video is not supported");
			embed = '<object width="700" height="393"><param name="movie" value="http://www.youtube.com/v/dvVAtdtOTeI?version=3&amp;hl=en_US&amp;rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/dvVAtdtOTeI?version=3&amp;hl=en_US&amp;rel=0" type="application/x-shockwave-flash" width="700" height="393" allowscriptaccess="always" allowfullscreen="true"></embed></object>';
	}
	
   	if(!jQuery.browser.msie) {
   		
   		jQuery('body').append('<div id="vidwrap"><div id="vid"><h1><a id="close">close</a><em>Energia &mdash; Energy that means business</em></h1>'+embed+'</div></div><div id="overlay"></div>');
   		
   		jQuery('#overlay').css({ opacity: 0, display: 'block' }).height( jQuery('body').height() ).fadeTo('300', 1.0, function () { 
   			
			if (scroll > 100) {
				var s = parseInt(jQuery('#vid').css('top')) + scroll;
				jQuery('#vid').css( 'top', s );
			}
   			
   			jQuery('#vidwrap').css({ display: 'block' });
   			jQuery('#close').bind('click', closer);
   			
   		});
   	} else {
   		
   		var pop = jQuery('<div/>').html('<div id="vidwrap"><div id="vid"><h1><a id="close">close</a><em>Energia &mdash; Energy that means business</em></h1>'+embed+'</div></div><div id="overlay"></div>');
   		
   		jQuery('body')[0].innerHTML = jQuery('body').html() + pop.html();
   		
		if (scroll > 100) {
			var s = parseInt(jQuery('#vid').css('top')) + scroll;
			jQuery('#vid').css( 'top', s );
		}
   		
   		jQuery('#vidwrap').css({ display: 'block' });
		
   		jQuery('#close, #vidwrap').bind('click', closer);
   		
   		setTimeout( function () { jQuery('#overlay').css({ display: 'block' }).height( jQuery('body').height() );}, 0);
   	}

}

closer = function () {
	
	jQuery('#overlay, #vidwrap').remove();
	
	if (jQuery('body.main').length) capcode();
	
}

