// JavaScript Document
$j(document).ready(function($) {	
	// on mouse over/out functions
	if (typeof $.fn.hoverIntent == 'function') {
		$('.cycleSS').hoverIntent(function() {showSlideNav($j)}, function() {hideSlideNav($j)});
	} else {
		$('.cycleSS').hover(function() {showSlideNav($j)}, function() {hideSlideNav($j)});
	}
	// Hide on page load...
	if ($('#SlideNextPrev')) {
		var initHideSlideNav = setTimeout("hideSlideNav($j)", 1000);	// delay in milliseconds
	}
	$('a[href$="#login"]').addClass('login').each( function() {
		theHref = $(this).attr('href');
		$(this).attr('href', theHref.replace('#login',''))
	});
	// Slide down top content (topReveal) 
	// -------------------------------------------------------------------
	$('.topReveal, a[href$="#topReveal"]').click( function() {
		// show/hide the content area
		$('#TopReveal').slideToggle(800,'easeOutQuart');
		// IE sucks feature 
		
		/*Vuthy comment*/
		/*if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) <= 8) {
			document.body.style.overflowX = 'scroll';  // force overflow-x = scroll, prevents IE scrollbar
		}*/
		$.scrollTo(document.body);
		return false;
	});
	
	/* IE6 warning */
	var IE6 = (navigator.userAgent.indexOf("MSIE 6")>=0) ? true : false;
	if(IE6){
		$(function(){	
			$("<div id='iewarn' style='top: 0px;'><div><h3>IE6 DETECTED: Currently Running in Compatibility Mode</h3><h4>This site is compatible with IE6, however your experience will be enhanced with a newer browser</h4><p>Internet Explorer 6 was released in August of 2001, and the latest version of IE6 was released in August of 2004.  By continuing to run Internet Explorer 6 you are open to any and all security vulnerabilities discovered since that date.  In March of 2011, Microsoft released version 9 of Internet Explorer that, in addition to providing greater security, is faster and more standards compliant than both version 6, 7 and 8 that came before it.</p> <br /><br /><br /><a class='external'  href='http://windows.microsoft.com/en-US/internet-explorer/downloads/ie'>Download Internet Explorer 9 NOW!</a>")
			.appendTo("body");
		});		
		$('#iewarn').slideToggle(800,'easeOutQuart');
		$.scrollTo(document.body);
		return false;
	}

	// image hover effects	
	// -------------------------------------------------------------------
	$("a.img").hover( function () {
		if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) <= 8) {
			$(this).stop(false, true).toggleClass('imgHover');
		} else {
			$(this).stop(false, true).toggleClass('imgHover', 200);
		}
	});
	
	// input lable replacement
	// -------------------------------------------------------------------
	$("label.overlabel").overlabel();
	// initialize anchor tag scrolling effect (scrollTo)
	// -------------------------------------------------------------------
	$j.localScroll();
	buttonStyles();
		
});

	// show slide navigation
	function showSlideNav($) {
		if ($('#SlideNextPrev')) {
			if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7) {
				$('#SlideNextPrev').css('display','block');
			} else {
				$('#SlideNextPrev').animate({ 'height': '30px' }, 300, function() {});
			}
		}		
	}
	// hide slide navigation
	function hideSlideNav($) {
		if ($('#SlideNextPrev')) {
			if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7) {
				$('#SlideNextPrev').css('display','none');
			} else {
			$('#SlideNextPrev').animate({ 'height': '0px' }, 400, function() {});
			}
		}
	}

	function buttonStyles() {
		// Button styles
		
		// This will style buttons to match the theme. If you don't want a button
		// styled, give it the class "noStyle" and it will be skipped.
		$j("button:not(:has(span),.noStyle), input[type='submit']:not(.noStyle), input[type='button']:not(.noStyle)").each(function(){
			var	b = $j(this),
				tt = b.html() || b.val();
			
			// convert submit inputs into buttons
			if (!b.html()) {
				b = ($j(this).attr('type') == 'submit') ? $j('<button type="submit">') : $j('<button>');
				b.insertAfter(this).addClass(this.className).attr('id',this.id);
				$j(this).remove();	// remove input
			}
			b.text('').addClass('btn').append($j('<span>').html(tt));	// rebuilds the button
		});
		
		// Get all styled buttons
		var styledButtons = $j('.btn');
		
		// Fix minor problem with Mozilla and WebKit rendering (can also be done adding this to CSS, 
		// button::-moz-focus-inner {border: none;}
		// @media screen and (-webkit-min-device-pixel-ratio:0) { button span {margin-top: -1px;} }
		if (jQuery.browser.mozilla || jQuery.browser.webkit) {
			styledButtons.children("span").css("margin-top", "-1px");
		}
		
		// Button hover class (IE 6 needs this)
		styledButtons.hover(
			function(){ $j(this).addClass('submitBtnHover'); },		// mouseover
			function(){ $j(this).removeClass('submitBtnHover'); }	// mouseout
		);
	}
