//------------------------------------
//	CORPORATE.JS
//	Author: 	Engage Interactive
//				
//				
//------------------------------------

//CUFON

Cufon.replace('nav#primary > ul > li > a',{
	textShadow:	'1px 1px #FFFFFF',
	hover: {
		color:	'#b70505'
	}
});

Cufon.replace('nav#secondary > ul > li > a:not(.on)',{
	hover: {
		color:	'#512698'
	}
});

Cufon.replace('nav#secondary > ul > li > a.on');


Cufon.replace('h3, .large, .intro_big, .brand_news dt',{ 
	textShadow:	'1px 1px #FFFFFF',
	hover:		{
		color:	'#b70505'
	}	  
});

Cufon.replace('#footer h3',{
	textShadow:	'1px 1px #000000'
});



$(function(){
//BEGIN jQuery

	// TARGET BLANK REPLACEMENT
	$('.external').attr('target','_blank');

	// Activate sub (sub) navs
	$('nav#primary > ul > li.dropdown').subnav();
	
	// Placeholder text for inputs
	$('input[placeholder]').placeholder();


//END jQuery
});

// Easing
jQuery.extend( jQuery.easing,{
	easeInOutExpo: function (x, t, b, c, d){
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	}
});

$.fn.subnav = function(subsub){  

	// Good or bad browser?
	if( $.browser.msie && $.browser.version < 9 ){
		var capable = false;
	}else{
		var capable = true;
	}

	return this.each(function(){

		// Variables
		var snav = false;	// Does a sub nav menu exist?
		var hnav = false;	// Are we hovering on either the nav item or the sub nav menu?
		var $dropdown;		// To use later
		var ddClass = '';	// To use later
		
		// Set the classes, based on capable and subsub variables
		capable == true ? ( subsub == true ? ddClass = 'dropdown subsub capable' : ddClass = 'dropdown capable' ) : ( subsub == true ? ddClass = 'dropdown subsub' : ddClass = 'dropdown' );
		
		// Create the sub nav menu and add it to the page
		$dropdown = $('<div/>',{
			'class': ddClass,
			html: '<ul>' + $(this).children('ul').html() + '</ul>',
			mouseleave: function(){
				hnav = false;
				setTimeout(cleanup, 100);
			},
			mouseenter: function(){
				hnav = true;
			}
		}).appendTo('body');
		
		if( !subsub ) $dropdown.find('.dropdown').subnav(true).children('ul').remove();

		// Hover over nav item
		$(this).mouseenter(function(e){

			// Hover is true
			hnav = true;

			// Does a sub nav menu already exist?
			if( snav == false ){

				// Find the x & y
				if( subsub ){
					var x = $(this).offset().left + 210;
					var y = $(this).offset().top;
				}else{
					var x = $(this).offset().left;
					var y = $(this).offset().top + 30;
				}

				$dropdown.css({top:y,left:x}).show();

				// Get the height
				var h = $dropdown.find('ul').height();
				
				// Animate it
				if( capable ){
					$dropdown.stop([]).css({opacity:0}).animate({height:h,opacity:1},500,'easeInOutExpo');
				}else{
					$dropdown.css({height:h});
				}
				
				// And now we have a sub nav
				snav = true;
				
				// Sub sub navs
				$dropdown.find('li.dropdown').mouseover(function(){
					$dropdown.siblings('.dropdown').hover(function(){
						hnav = true;
					},function(){
						hnav = false;
						setTimeout(cleanup, 100);
					});
				});
			
			}else{
				
				$dropdown.stop([]).animate({height:$dropdown.find('ul').height(),opacity:1},400,'easeInOutExpo');
				
			}
			
		});
		
		// Leaving the nav item, hover is now false, set timer to remove sub nav
		$(this).mouseleave(function(){
			hnav = false;
			setTimeout(cleanup, 200);
		});
		
		// Remove the sub nav as long as hnav is false
		function cleanup(){
			if( hnav == false ){
				if( capable ){
					$dropdown.stop([]).animate({height:0,opacity:0},500,'easeInOutExpo',function(){
						$(this).hide();
						snav = false;
					});
				}else{
					$dropdown.hide();
					snav = false;
				}
			}
		}

	});

};

$.fn.placeholder = function(){
	
	if( $('html').hasClass('webkit') == false ){

		return this.each(function(){
			
			var $this = $(this);
			var ph = $this.attr('placeholder');
			
			$this.attr('value',ph);
			
			$this.focus(function(){
				if( $this.attr('value') == ph ){
					$this.attr('value','');
				}
			});
			
			$this.blur(function(){
				if( $this.attr('value') == '' ){
					$this.attr('value',ph);
				}
			});
			
			$this.closest('form').submit(function(){
				if( $this.attr('value') == ph ){
					$this.attr('value','');
				}
			});
			
		});
	}

};

/*
 * jQuery Timer Plugin
 * http://www.evanbot.com/article/jquery-timer-plugin/23
 *
 * @version      1.0
 * @copyright    2009 Evan Byrne (http://www.evanbot.com)
 */

jQuery.timer = function(time,func,callback){
	var a = {timer:setTimeout(func,time),callback:null}
	if(typeof(callback) == 'function'){a.callback = callback;}
	return a;
};

jQuery.clearTimer = function(a){
	clearTimeout(a.timer);
	if(typeof(a.callback) == 'function'){a.callback();};
	return this;
};

//BEGIN CONTACT FORM
$(function(){
	$('#show_brand').hide();
	
	$('#select').change(function(){
		if ($(this).val()==118)
		{
			$('#show_brand').fadeIn('fast');
		} else {
			$('#show_brand').fadeOut('fast');
		}
	});
//END jQuery
});
