jQuery.noConflict();
jQuery(document).ready(function($){
//$(document).ready(function(){
	
// -------------------------------------------------------------------------------------------
// Make last TD align right for dynamic xCat forms and tables
// -------------------------------------------------------------------------------------------

//$(".DLGRowTROne td:last-child:not(:first-child), .DLGRowTROne:last-child:not(:first-child), .DLGRowTRTwo td:last-child:not(:first-child), .DLGRowTRTwo:last-child:not(:first-child), .DLGHeaderTD:last-child:not(:first-child), .DLGTitleTD:last-child:not(:first-child), .DLGDataTD:last-child:not(:first-child)").css({'text-align': 'right', 'padding-right': '15px', 'white-space': 'nowrap'})

//$(".DLGRowTROne td:last-child:not(:first-child), .DLGRowTROne:last-child:not(:first-child), .DLGRowTRTwo td:last-child:not(:first-child), .DLGRowTRTwo:last-child:not(:first-child), .DLGHeaderTD:last-child:not(:first-child), .DLGTitleTD:last-child:not(:first-child), .DLGDataTD:last-child:not(:first-child)").wrapInner('<div class="xCatLastTD" />'); $('.xCatLastTD').css({ 'text-align': 'right' });

// -------------------------------------------------------------------------------------------
// Fix for fire fox width issues with the upload form field
// -------------------------------------------------------------------------------------------

$('input[type="file"]').attr('size', '30');

// -------------------------------------------------------------------------------------------
// Google Analytics
// -------------------------------------------------------------------------------------------

//$.glamGA(''); 

// -------------------------------------------------------------------------------------------
// Dynamic Copyright Date
// -------------------------------------------------------------------------------------------

//$("#year").text( (new Date).getFullYear() );

// -------------------------------------------------------------------------------------------
// Superfish dropdown menus
// -------------------------------------------------------------------------------------------

$('ul.sf-menu').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',
		'z-index': '100',
		'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'
};
 
$('#content2 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/icons/'+image+'" alt="Link Icon" align="absmiddle" style="margin:2px 3px 0px 4px;">');
	  }
	}
});	

// -------------------------------------------------------------------------------------------
// Tabs 
// -------------------------------------------------------------------------------------------

$(".tabs h6").each(function() {
	$(this).nextUntil("h6").wrapAll('<div class="tabbody" />');
	});
$(".tabs").accessibleTabs({
	tabhead: 'h6',
	fx:"fadeIn",
	tabbody:'.tabbody'
});

// -------------------------------------------------------------------------------------------
// Slides code
// -------------------------------------------------------------------------------------------

// Gets the CSS for the slider 
//if ($('.slides_container').length) { // implies *not* zero  
//	var SliderCSS = 'js/slider/slider.css'
//	if(document.createStyleSheet) {
//		try { document.createStyleSheet(SliderCSS); } catch (e) { }
//	}
//	else {
//		var css;
//		css         = document.createElement('link');
//		css.rel     = 'stylesheet';
//		css.type    = 'text/css';
//		css.media   = "all";
//		css.href    = SliderCSS;
//		document.getElementsByTagName("head")[0].appendChild(css);
//	}
//}
//else {
//    // do nothing 
//}

$('#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: false,
	autoHeightSpeed: 350,
	randomize: false,
	crossfade: false,
	effect: 'slide',
	// Get the starting slide
	start: 1,
	animationStart: function(){
					$('.caption').animate({
						left:-200
					},100);					
				},
				animationComplete: function(){
					$('.caption').animate({
						left:0
					},200);
				},
				slidesLoaded: function() {
					$('.caption').animate({
						left:0
					},200);
				}			
});
$('#slides-mb-spotlight').slides({
	container: 'slides_container',
	preload: true,
	preloadImage: 'img/loading.gif',
	pagination: false,
	generatePagination: false,
	generateNextPrev: false,
	play: 7000,
	pause: 2500,
	slideSpeed: 350,
	fadeSpeed: 350,
	hoverPause: true,
	autoHeight: true,
	autoHeightSpeed: 350,
	randomize: true,
	crossfade: false,
	effect: 'fade'
});


//------------------------------------------------------------------------------------------
//Grab XML file of images, and set Himages array equal to the array from the xml
//------------------------------------------------------------------------------------------
//$.ajax({
//    type: "GET",
//    url: "/images/LexMundiWebsite/images_GenBanner/PlayListXML.asp",
//    dataType: "xml",
//    success: parseXml
//});
//
//
//function parseXml(xml)
//{
//  var Himages = new Array();
//
//  //find every xml node with a tag of location and add it to Himages[]
//  var counter = 0;
//  $(xml).find("location").each(function()
//  {
//    Himages[counter] = $(this).text();
//            counter++;
//  });
//  

// -------------------------------------------------------------------------------------------
// Random Image on Page Load using above asp to render XML
// -------------------------------------------------------------------------------------------  
//  if ($('.headerimage').length) { // implies *not* zero  
//} else {
//    $('<div class="clear span-24 last headerimage"><img src="' + Himages[Math.floor(Math.random() * Himages.length)] + '"></div>').insertAfter('.top-nav-default');
//} 
//
//}

// -------------------------------------------------------------------------------------------
// Login form to replace any login links and add new modal UI dialog
// -------------------------------------------------------------------------------------------  

//function parseURL(getID, testString)
//{
//  getID = getID.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
//  var regexS = "[\\?&]"+getID+"=([^&#]*)";
//  var regex = new RegExp( regexS );
//  var results = regex.exec( testString );
//  if( results == null )
//	return "";
//  else
//	return results[1];
//}
//
//var SnID = "";
//var foundID = false; //Stop parsing anchor tags for a session ID once one has been found.
//
//var loginPath = "https://www.partners.net/Login.asp"; // Define the path to the login page from the current page.
//                        
////Search for login link, and replace it.
//var pageLoginId = "login";
//var testHref = "";
//$("a").each(function(){
//            if($(this).attr("href")){
//                        testHref = $(this).attr("href");
//                        if(testHref.search(/login.asp/i) != -1){
//                                    $(this).attr("href", "javascript:void(0);");
//                                    if($(this).attr("id")){
//                                                pageLoginId = $(this).attr("id");
//                                    }
//                                    else{
//                                                $(this).attr("id", pageLoginId);
//                                    }
//                        }
//							//Search for session ID to pass with the login.
//							if(!foundID){
//								SnID = parseURL("SnID", testHref);								
//								if(SnID.length){
//									foundID = true;
//								}
//							}
//            }
//});
//
//if(!$("#dialog-loginFRM").length){                    
////Add login box. Strings in javascript must remain on one line, or an error will occur.
//$("body").append("<div id='dialog-loginFRM' title='Member Login' style='display:none;'><form action='"+ loginPath +"' method='post' id='loginFRM'><input type='hidden' name='MODE' value='VALIDATELOGIN'><input type='hidden' name='Login_RedirectURL'><input type='hidden' name='Login_Redirect' value='False'><input type='hidden' name='SnID' value='"+ SnID +"'><label for='email'>Email</label><input type='text' name='Login_UserID' id='Login_UserID' class='text ui-widget-content ui-corner-all' /><label for='password'>Password</label><input type='password' name='Login_Pswd' id='password' class='text ui-widget-content ui-corner-all' /><input type='checkbox' name='Login_Remember' value='True' ID='Login_Remember_ID' class='DLGControl' />Click here to remember me.<input type='hidden' name='Login_Remember_SENT' value='1'><div class='forgot-pass'><strong>Forgot your password?</strong> If you have forgotten your password or do not have one please type your email address in the box above and click on the login button. Your password will be emailed to you.</div></form></div>");       
//}
//$( "#dialog-loginFRM" ).dialog({
//            title: 'Member Login',
//            autoOpen: false,
//            show: 'fade',
//            //height: 300,
//            //width: 350,
//            modal: true,
//            buttons: {
//						Login: function() {
//									$('#loginFRM').trigger('submit');
//			   },
//						Cancel: function() {
//									$(this).dialog('close');
//			   }
//			}
//});
//$( "#" + pageLoginId )
//            //.button()
//            .click(function() {
//                        $( "#dialog-loginFRM" ).dialog( "open" );
//});                     
//            
//$('.ui-widget-overlay').live("click", function() {
//             //Close the dialog
//             $('#dialog-loginFRM').dialog('close');
//});

// -------------------------------------------------------------------------------------------
// Cufon font replacement
// -------------------------------------------------------------------------------------------
Cufon.replace('h4, .sidebar h3, h2, h1, #footer', {hover:true});
                Cufon.now();

// -------------------------------------------------------------------------------------------
// Toggle div's with class .toggleGrid
// -------------------------------------------------------------------------------------------
$.extend($.easing, {
	easeInOutCirc: function (x, t, b, c, d) { 
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b; 
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b; 
	}
});

var showText='+ Show Options';
var hideText='- Hide Options';
var is_visible = false;  

$('.toggleGrid').before(' <a href="#" class="toggleLink">'+showText+'</a> ');
$('.toggleGrid').css({ 
		width: '100%'
}); 
$('.toggleGrid').hide();
$('a.toggleLink').click(function() {
	is_visible = !is_visible;
	$(this).html( ($(this).html() == hideText) ? showText : hideText);
	$(this).next(".toggleGrid").toggle('fast', "easeInOutCirc");
	return false; 
});


// -------------------------------------------------------------------------------------------
// $(document).ready CLOSE
// -------------------------------------------------------------------------------------------

});

	
// -------------------------------------------------------------------------------------------
// Equal Heights
// -------------------------------------------------------------------------------------------
	
//$.fn.equalHeights = function() {
//	var maxHeight = 0;
//	$(this).each(function(index){
//		var height = $(this).height();
//
//		if (maxHeight < height) {
//			maxHeight = height
//		}
//   });
//   $(this).height(maxHeight);
//}
//$(".content2, .r-nav2").equalHeights();



//---------------------------------------------------------------------------------
//  Parse dates from <div class="date"> [mm]/[dd]/[yyyy] </div>
//  and convert them to the following:
//										<div class="parsed-date">
//											<span class="day">[dd]</span>
//											<span class="month">[Mnth]</span>
//											<span class="year">[yyyy]</span>	
//										</div>
//---------------------------------------------------------------------------------

//$(function(){
//
//	$(".date").each(function(){
//		
//		var fullDate = $(this).text();
//		
//		fullDate = fullDate.replace(/\s/g, "");
//		
//		var temp = new Array();
//		temp = fullDate.split("/");
//		
//		var month = "";
//		var day = temp[1];
//		var year = temp[2];
//		
//		switch (temp[0]) {
//			case "00" : month="Jan"; break;
//			case "01" : month="Feb"; break;			
//			case "02" : month="Mar"; break;
//			case "03" : month="Apr"; break;
//			case "04" : month="May"; break;		
//			case "05" :	month="Jun"; break;
//			case "06" :	month="Jul"; break;
//			case "07" :	month="Aug"; break;
//			case "08" :	month="Sep"; break;
//			case "09" :	month="Oct"; break;			
//			case "10" :	month="Nov"; break;
//			case "11" :	month="Dec"; break;
//			default : month= "";
//		}
//		
//		var newContent =  "<span class='day'>"  + day +"</span>";
//		    newContent += "<span class='month'>"+ month +"</span>";
//			newContent += "<span class='year'>" + year +"</span>";
//		
//		$(this).html(newContent);
//		$(this).attr("class", "parsed-date");
//	});
//
//});
