$.noConflict();
jQuery(document).ready(function($){

//$("#year").text( (new Date).getFullYear() );

// -------------------------------------------------------------------------------------------
// Superfish dropdown menus
// -------------------------------------------------------------------------------------------

$('ul.tmenu').supersubs({ 
	minWidth:    12,   // minimum width of sub-menus in em units 
	maxWidth:    27,   // maximum width of sub-menus in em units 
	extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
					   // due to slight rounding differences and font-family 
}).superfish({ 
	hoverClass:   'sfHover',          			  // the class applied to hovered list items 
	pathClass:    'TNCurrent', 			  		  // the class you have applied to list items that lead to the current page 
	pathLevels:   1,                  			  // the number of levels of submenus that remain open or are restored using pathClass 
	delay:        200,               			  // the delay in milliseconds that the mouse can remain outside a submenu without it closing 
	animation:    {opacity:'show',height:'show'},  // fade-in and slide-down animation 
	speed:        'fast',                          // faster animation speed 
	autoArrows:   true,                            // disable generation of arrow mark-up 
	dropShadows:  true                             // disable drop shadows 
}); 

// -------------------------------------------------------------------------------------------
// Scroll to top
// -------------------------------------------------------------------------------------------

var blue_css = { background: '#E5F6FE',	color: '#4D9FBF', border: '2px solid #ADD9ED' }
var green_css = { background: '#CDE6AC', color: '#58792E', border: '2px solid #A9DB66' }
var red_css = { background: '#f28279', color: '#9C2F2F', border: '2px solid #CE6F6F' }
var dark_css = { background: '#404040',	color: '#f3f3f3', border: '2px solid #303030' }
var light_css = { background: '#f1f1f1', color: '#454545', border: '2px solid #E2E2E2' }
var cream_css = { background: '#F0DE7D', color: '#A27D35', border: '2px solid #F9E98E' } 
var taup_css = { background: '#E8E6E3', color: '#928b81', border: '2px solid #D7D3D0' }
		
/*---Creates the scroll to top link---*/
$('body').prepend('<a href="javascript:;" id="toTop">^ Scroll to Top</a>');
	$('#toTop').css({ 
		width: '85px',
		'font-size': '10px',
		padding: '5px',
		position: 'fixed',
		bottom: '10px',
		right: '10px',
		cursor: 'pointer',
		'text-align': 'center',
		'text-decoration': 'none',
		'font-family': 'UniversCondensed'
		//color: '#666',
		//background: '#f1f1f1',
		//border: '1px solid #ccc'
});
$('#toTop').css(dark_css)
			
/*---Starts the scroll to top function that uses the link above. This must come after the link is created above.---*/
$(function() {
	$("#toTop").scrollToTop({speed:800});
});

// -------------------------------------------------------------------------------------------
// Clear input field of values
// -------------------------------------------------------------------------------------------

$.fn.clearDefault = function(){  
	return this.each(function(){  
		var default_value = $(this).val();  
		$(this).focus(function(){  
			if ($(this).val() == default_value)  
						  $(this).val("");  
		});  
		$(this).blur(function(){  
			if ($(this).val() == "")  
						  $(this).val(default_value);  
		});  
	});  
};
$('.searchfield').clearDefault(); 
	
// -------------------------------------------------------------------------------------------
// Adds a focus class to the parent element so you can see what field you are on
// -------------------------------------------------------------------------------------------
			
$(".content input").focus(function() {
	$(this).parent().addClass("curFocus")
});
	$(".content input").blur(function() {
	$(this).parent().removeClass("curFocus")
});
				

// -------------------------------------------------------------------------------------------
// Adds the icons after links and makes external links open in new window
// -------------------------------------------------------------------------------------------

//var fileTypes = {
//  doc: 'doc.gif',
//  xls: 'xls.gif',
//  pdf: 'pdf.gif'
//};
// 
//$('#content a, .paddingMC a').each(function() {
// 
//  var $a = $(this);
//  var href = $a.attr('href');
//  
//  if (!$a.children('img').size()) { 
//	  if ((this.href.match(/^http\:/i)) && (!this.href.match(document.domain))) {				 
//		// use a special image for external links
//		var image = 'extlink.gif';
//		//makes external links open in new window
//		$a.attr("target", "_blank"); 
//	  } 				  
//	  else {					  
//			if (this.href.match(/^mailto\:/i)) {				 
//			// use a special image for mailto links
//			var image = 'mailto.gif';					
//			}
//			else {
//			// get the extension from the href
//			var hrefArray = this.href.split('.');
//			var extension = hrefArray[hrefArray.length - 1];
//			var image = fileTypes[extension];
//		  }
//	  }
//	   if (image) {
//		$a.after('<img src="/images/nyipla/Template/css/lib/img/icons/'+image+'" alt="Link Icon" align="absmiddle" style="margin:0px 3px 0px 4px;">');
//	  }
//	}
//});	

// -------------------------------------------------------------------------------------------
// Makes links to the following file types open in new windows
// -------------------------------------------------------------------------------------------
//$.each(function() {
//$("a[href*=.pdf]").attr("target", "_blank");
//$("a[href*=.doc]").attr("target", "_blank");  
//$("a[href*=.xls]").attr("target", "_blank");  
//$("a[href*=.ppt]").attr("target", "_blank"); 
//$("a[href*=.pps]").attr("target", "_blank"); 
//});


// -------------------------------------------------------------------------------------------
// Tabs 
// -------------------------------------------------------------------------------------------

$(".tabs h6").each(function() {
	$(this).nextUntil("h6").wrapAll('<div class="tabbody" />');
	});
$(".tabs").accessibleTabs({
	tabhead: 'h6',
	fx:"fadeIn",
	tabbody:'.tabbody'
});
$(".tabsLexLink h6").each(function() {
	$(this).nextUntil("h6").wrapAll('<div class="tabbody" />');
	});
$(".tabsLexLink").accessibleTabs({
	tabhead: 'h6',
	fx:"fadeIn",
	tabbody:'.tabbody'
});

// -------------------------------------------------------------------------------------------
// Slides code
// -------------------------------------------------------------------------------------------

$('#slides').slides({
	container: 'slides_container',
	preload: true,
	preloadImage: 'img/loading.gif',
	pagination: true,
	generatePagination: true,
	generateNextPrev: false,
	play: 7000,
	pause: 2500,
	slideSpeed: 350,
	fadeSpeed: 350,
	hoverPause: true,
	autoHeight: true,
	autoHeightSpeed: 350,
	randomize: false,
	crossfade: false,
	effect: 'slide',
	// Get the starting slide
	start: 1			
});


// -------------------------------------------------------------------------------------------
// Equal Heights
// -------------------------------------------------------------------------------------------
	
$.fn.equalHeights = function() {
	var maxHeight = 0;
	$(this).each(function(index){
		var height = $(this).height();

		if (maxHeight < height) {
			maxHeight = height
		}
   });
   $(this).height(maxHeight);
}
$(".LeftNav, .content").equalHeights();




// -------------------------------------------------------------------------------------------
// Random Image on Page Load
// -------------------------------------------------------------------------------------------
var images = ['DefaultHIMG1.jpg', 'DefaultHIMG2.jpg', 'DefaultHIMG3.jpg', 'DefaultHIMG4.jpg', 'DefaultHIMG5.jpg', 'DefaultHIMG6.jpg', 'DefaultHIMG7.jpg', 'DefaultHIMG7.jpg', 'DefaultHIMG8.jpg', 'DefaultHIMG9.jpg', 'DefaultHIMG10.jpg'];
//Set a random header background with jQuery and CSS background-image.
$('#headerTEST').css({'background-image': 'url(/images/lexmundi/Template/New/images/' + images[Math.floor(Math.random() * images.length)] + ')'});
//Insert a random banner or picture with jQuery and DOM injection
$('<div class="clear span-24 last headerimage"><img src="/images/lexmundi/Template/New/images/' + images[Math.floor(Math.random() * images.length)] + '"></div>').insertAfter('.top-nav-default');


// -------------------------------------------------------------------------------------------
// $(document).ready CLOSE
// -------------------------------------------------------------------------------------------
	
});
