// fixes $ / mrm.$ jQuery conflict call between site and gmds app
var mrm = mrm || {}; mrm.$ = mrm.$ || jQuery;

// override if console unavailable.
if (typeof console == "undefined") {
	window.console = {
		log: function () {}
	};
}

function locationWrapper( url ){
	if ( $.browser.msie ) {
		var referLink = document.createElement('a');
		referLink.href = url;
		document.body.appendChild(referLink);
		referLink.click();
	} else {
		window.location = url;
	}
}

function updateOnOrientationChange(){
	switch( window.orientation ){
		case 0:
		case 180:
			//alert( 'Portrait' );
			switch( navigator.platform ){
				case 'iPad':
					$( 'meta[name="viewport"]' ).attr( 'content', 'width = 980px, initial-scale = .78, minimum-scale = .5, maximum-scale = 3' );
					break;
				case 'iPhone':
					$( 'meta[name="viewport"]' ).attr( 'content', 'width = 980px, initial-scale = 1, minimum-scale = .5, maximum-scale = 3' );
					break;
			}
			break;
		default:
			//alert( 'Landscape' );
			switch( true ){
				case $( 'body' ).hasClass( 'homepage' ):
					$( 'meta[name="viewport"]' ).attr( 'content', 'width = 1024px;, initial-scale = 1, minimum-scale = .5, maximum-scale = 3' );
					break;
				default:
					$( 'meta[name="viewport"]' ).attr( 'content', 'width = device-width, initial-scale = 1, minimum-scale = .5, maximum-scale = 3' );
			}
	}
}
updateOnOrientationChange();
$(document).ready( function(){
//	alert(
//		"$( 'body.brandpage div#content' ).height() " + $( 'body.brandpage div#content' ).height()
//	);
//	alert( 
//		"navigator.platform " + navigator.platform + "\n" +
//		"window height " + $( window ).height() + "\n" +
//		"body height " + $( 'body' ).height() + "\n" +
//		"window width " + $( window ).width() + "\n" +
//		"body width " + $( 'body' ).width() + "\n"
//	);
	if( navigator.platform == 'iPad' || navigator.platform == 'iPhone' ){
		$( 'body' ).resize( function(){ updateOnOrientationChange(); });
		updateOnOrientationChange();
	}
	$( 'div#primaryNavigation > ul' ).fill({
		elements : 'li',
		fill     : 'li#blackFill'
	});

	//$( 'div#primaryNavigation > ul' ).css({ width : 980 });
	//alert( "$( 'div#primaryNavigation > ul' ).width() " + $( 'div#primaryNavigation > ul' ).width() );

	$( 'li#vehicles, li#vision, li#company' ).primaryNavigationSlideDown();

	$( 'li#GMLogo' ).click( function(){
		location.href = "/content/gmcom/home.html";
	});

	$( 'li#contactUs, li#allGMSites' ).each( function(){
		if( typeof( Cufon ) == 'function' && Cufon.replace ){
			Cufon.replace( $( this ).children( 'h2' ).children( 'a' ), { fontFamily: 'gotham-bold', hover: true });
		}
	});

	$( '#primaryNavigation li form input' ).focus( function(){
		if( $( this ).attr( 'value' ) == 'SEARCH' )
			$( this ).attr( 'value', '' )
	}).blur( function(){
		if( $( this ).attr( 'value' ).length <= 0 )
			$( this ).attr( 'value', 'SEARCH' );
	});
	
	$('ul.right li').eq(7).addClass("last");
});
