// JavaScript Document
function sortNumber( a , b ){
	return b - a;
}

var navTimeOut,speed = 500;
var scrollto = 0;

$( function(){

$("a[href*=.pdf]").click(function(){
	$(this).attr({"target":"_blank"});
});

function showMenu(){

	var $this = $( this );
	
	var jChildMenu = $this.find( 'div' );
	
	$this.children( 'a' ).addClass( 'active' );
	
	jChildMenu.slideDown( speed );

}		
function hideMenu(){

	var $this = $( this );
	
	var jChildMenu = $this.find( 'div' );
	
	$this.children( 'a' ).removeClass( 'active' );
	
	jChildMenu.slideUp( speed );


}		
function scroll(){
   $("html:not(:animated),body:not(:animated)").animate({ scrollTop: scrollto}, 800 );
   return false;
}

var config = {    
     over: showMenu,     
     timeout: navTimeOut,     
     out: hideMenu  
};

$( 'ul#main-nav li' ).hoverIntent( config );




$( 'div#band' ).fadeTo( 0 , .4 );
	
for(i=1; i<=2; i++) {
	setModuleHeights('row' + i)
}

function setModuleHeights(row) {
	var heightArray = [];	
	var $row = $('div.' + row + ' div.module-content');
	
	$row.each(function(index) {
    var height = $(this).height();
		heightArray.push(height);
  });
	
	heightArray = heightArray.sort(sortNumber);	
	$row.height(heightArray[0]);
	
	return true;
}

if( location.pathname.length > 1){
	
	scroll();
	
}

//sidebar navigation

$( 'div#side-bar div.menu blockquote a.parent' )
	.click( function( event ){
			     
		var $this = $( this );		    
		
		//get the parent of the blockquote
		var $blockquote = $this.parent();
		
		var $parent = $blockquote.parent();
		
	
		if( $this.hasClass( 'opened' ) ){
			
			event.preventDefault();
			
			return false;
			
		}
		
		$( 'div#side-bar div.menu blockquote a' ).removeClass( 'opened').addClass('closed' );
		
		$this.addClass( 'opened' ).removeClass('closed');
		
		//close all list
		$( 'div.menu' ).find( 'ul:first' ).stop().slideUp();
		
		$( 'div#side-bar div.menu blockquote a.parent img' ).attr( 'src', '/site_media/images/icons/icon-closed-arrow.gif' );
		
		
		$this.find( 'img' ).attr( 'src', '/site_media/images/icons/icon-open-arrow.gif' );
		
		$( 'div#side-bar div.menu ul li ul' ).stop().slideUp();
		
		//open the parent list of links
		$parent.find( 'ul:first' ).stop().slideDown();
		
		event.preventDefault();		     
});

$( 'div#side-bar div.menu ul li a.toggle' )
	.click( function( event ){
	
	var $this = $( this );
	
	var $parent = $this.parent();
	

	if( $this.hasClass('opened') ){
		
		event.preventDefault();
		
		return false;
		
	}
	
	$( 'div#side-bar div.menu ul li a' ).removeClass('opened').addClass('closed');
	
	
	$this.addClass( 'opened' );
	
	$( 'div#side-bar div.menu ul li a.toggle img' ).attr( 'src', '/site_media/images/icons/icon-sidebar-plus.gif');
	
	$this.find( 'img' ).attr( 'src', '/site_media/images/icons/icon-sidebar-minus.gif' );
	
	$( 'div#side-bar div.menu ul li ul' ).slideUp();
	
	$parent.find( 'ul' ).slideDown();
	
	event.preventDefault();

});


$( 'div#side-bar div.menu a.child,div#side-bar div.menu a.products,div#side-bar blockquote a' ).each( function( index ){
	
	var $this = $( this );
	
	var text = $this.text();

	if( text.length > 40 ){
		$( this ).text( text.substr(0 , 30 ) + '...' );
	}
});
//breadcrumbs

$( 'ul#breadcrumbs li' ).filter(":not(:last)").append( '&nbsp;<img src="/site_media/images/icons/icon-breadcrumb-arrow.png" alt="" />&nbsp;'  );
var browser		= navigator.appName
var ver			= navigator.appVersion
var thestart	= parseFloat(ver.indexOf("MSIE"))+1 
var brow_ver	= parseFloat(ver.substring(thestart+4,thestart+7))
if ((browser=="Microsoft Internet Explorer") && (brow_ver < 7)){
//	window.location="http://www.microsoft.com/windows/internet-explorer/default.aspx";
}
if ((browser=="Microsoft Internet Explorer") && (brow_ver < 8)){
	//$( 'div#interior,div#side-bar').css('min-height','200px');
}

$('a.external').attr( 'target','_blank');

$("a.fancybox").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	true
	});
	
	$("a#inline").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	true,
		'width'		: 319,
    'height'		: 239,
    'autoDimensions': false,
    'overlayShow'	:	true,
    'padding'		: 0,
    'margin': 0,
	});


    $("a.youtube").click(function() {
    	$.fancybox({
    		'transitionIn'	:	'elastic',
    		'transitionOut'	:	'elastic',
    		'speedIn'		:	600, 
    		'speedOut'		:	200, 
    		'overlayShow'	:	true,
    		'padding'		: 0,
    		'autoScale'		: false,
    		'transitionIn'	: 'none',
    		'transitionOut'	: 'none',
    		'title'			: this.title,
    		'width'		: 680,
    		'height'		: 495,
    		'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
    		'type'			: 'swf',
    		'swf'			: {
    		 	'wmode'		: 'transparent',
		'allowfullscreen'	: 'true'
    			}
    		});

    	return false;
    });


/*reordering the menu */
var list_to_move = $( 'div#shelters-arrange div.menu:eq(1)');
$( 'div#shelters-arrange').append( list_to_move );

var list_to_move = $('div#power-nav div.menu:eq(1)');
$('div#power-nav' ).prepend( list_to_move );

var newList = $( '<ul class="hide"/>' );

var e_list = $( 'div#control-arrange div.menu:eq(1) ul > li:not(.bar)');
var menu_title = $( 'div#control-arrange div.menu:eq(1) li.bar a.menu-title' )
var arrow = $( 'div#control-arrange div.menu:eq(1) li.bar a.toggle-arrow' )

list = [e_list.eq(1), e_list.eq(3),e_list.eq(2),e_list.eq(4),e_list.eq(5),e_list.eq(0)]

$.each( list , function( index , value ){
	
	newList.append( value );
	
});

if( $( 'div#control-arrange div.menu:eq(1) li.bar a:eq(0)' ).hasClass( 'open' ) ){
	newList.removeClass( 'hide' );	
	
}
$( 'div#control-arrange div.menu:eq(1) li:not( .bar' ).empty();
$( 'div#control-arrange div.menu:eq(1) li.bar' ).prepend( arrow, menu_title, newList );


});

/*
1. HDT Environmental Control Units
2. Nordic™ ECU
3. Non-Powered Heaters
4. Self-Powered Heaters
5. Cargo Heaters
*/

