/*=========================================================


	Site Name   Chrysler Collection
	File Name   function.js

	Create Date 2008/11/04
	Update Date 2008/11/04


==========================================================*/

/*========================================================*/
/*                                                        */
/*                                                        */
/*		1. Fullscreen Function                    */
/*                                                        */
/*		2. Pop Up Window Function                 */
/*                                                        */
/*		3. RollOver Images Function*              */
/*                                                        */
/*		4. External Link Function*                */
/*                                                        */
/*		5. Fade Effect Function*                  */
/*                                                        */
/*		6. Add Pseudo Class Function*             */
/*                                                        */
/*		* Require jquery.js                       */
/*                                                        */
/*                                                        */
/*========================================================*/

/*----------------------------------------------------------

	1. Fullscreen Function

-----------------------------------------------------------*/

function getFullscreen(thePage){
	var winWidth = screen.availWidth;
	var winHeight = screen.availHeight;
	window.open(thePage,"title","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=no,resizable=no,left=0,top=0,width="+winWidth+",height="+winHeight);
}

/*----------------------------------------------------------

	2. Pop Up Window Function

-----------------------------------------------------------*/

function openBrWindow(url, name, myW, myH, scrollAndResize) {
	posX = (screen.availWidth - myW) / 2;
	posY = (screen.availHeight - myH) / 2;
	newWin = window.open(url, name, "left="+posX+", top="+posY+",width="+myW+", height="+myH+", scrollbars="+scrollAndResize+", resizable="+scrollAndResize);
}

/*----------------------------------------------------------

	3. RollOver Images Function (require jquery.js)

-----------------------------------------------------------*/

$(function(){
	var image_cache = new Object();

	$("img.btn").each(function(i){
		var imgsrc = this.src;
		var dot = this.src.lastIndexOf('.');
		var imgsrc_on = this.src.substr(0, dot) + '_o' + this.src.substr(dot, 4);
		image_cache[this.src] = new Image();
		image_cache[this.src].src = imgsrc_on;

		$(this).hover(
			function(){ this.src = imgsrc_on;},
			function(){ this.src = imgsrc;}
		);
	});
})

/*----------------------------------------------------------

	4. External Link Function (require jquery.js)

-----------------------------------------------------------*/

$(function(){
	var popupEvent = function(event){
		window.open(this.href);
		event.preventDefault();
		event.stopPropagation();
	}

	$("a.externalLink").each(function(i) {
		$(this).click(popupEvent);
		$(this).keypress(popupEvent);
	});
})

/*----------------------------------------------------------

	5. Fade Effect Function (require jquery.js)

-----------------------------------------------------------*/

$(function(){
	$(".fadeImg").hover(
		function(){$(this).stop().fadeTo(300, 0.6);},
		function(){$(this).stop().fadeTo(300, 1);}
	);
})

/*----------------------------------------------------------

	6. Add Pseudo Class Function (require jquery.js)

-----------------------------------------------------------*/

$(function(){
	$(':first-child').addClass('firstChild');
	$(':last-child').addClass('lastChild');
})

/*----------------------------------------------------------

	7. Smooth Scroll Function (require jquery.js)

	* Not works with newest version jQuery

-----------------------------------------------------------*/

$(function(){
	$('a').each(function(i){
		if(this.href.indexOf('#') != -1) {
			$(this).click(function(){
				var targetID = this.href.split('#');
				targetID = '#' + targetID[1];
				$(targetID).ScrollTo(500,'easeout');
				return false;
			});
		}
	});
})