var $j = jQuery.noConflict();
$j(document).ready(function(){
	/* Header */	
	$j("div.Amusement").hover( function(){
		$j(".HeaderReiterHome").addClass("HeaderReiterAmusement");
		$j(".HeaderReiterHome").removeClass("HeaderReiterHome");
		
		$j(".HeaderContent").addClass("HeaderContentAmusement");
		$j(".HeaderContent").removeClass("HeaderContent");
	}, function() {
		$j(".HeaderReiterAmusement").addClass("HeaderReiterHome");
		$j(".HeaderReiterAmusement").removeClass("HeaderReiterAmusement");
		
		$j(".HeaderContentAmusement").addClass("HeaderContent");
		$j(".HeaderContentAmusement").removeClass("HeaderContentAmusement");			
	});
	$j("div.Transportation").hover( function(){
		$j(".HeaderReiterHome").addClass("HeaderReiterTransportation");
		$j(".HeaderReiterHome").removeClass("HeaderReiterHome");
		
		$j(".HeaderContent").addClass("HeaderContentTransportation");
		$j(".HeaderContent").removeClass("HeaderContent");			
	}, function() {
		$j(".HeaderReiterTransportation").addClass("HeaderReiterHome");
		$j(".HeaderReiterTransportation").removeClass("HeaderReiterTransportation");
		
		$j(".HeaderContentTransportation").addClass("HeaderContent");
		$j(".HeaderContentTransportation").removeClass("HeaderContentTransportation");				
	});	

	/* Bg Slide, works in all Browsers exept IE6 */
	if (!jQuery.browser.msie || (jQuery.browser.msie && jQuery.browser.version.substr(0,3)!="6.0")){
		setTimeout(function() {
		$j(".BackgroundImageRotator img").each(function(i){
														if ($j(this).attr("src") == "")
														$j(this).attr("src", $j(this).attr("alt"));
														});
		}, 500);
	
		$j(function() {
			setInterval( "slideSwitch()", 10000 );
		});
	}
	
	$j('.page_margins').center();
});	

/* Bg Slide	*/
function slideSwitch() {
	
	var active = $j('.BackgroundImageRotator img.active');
	
	if (active.length == 0) active = $j('.BackgroundImageRotator img:first');

	var next = active.next("img").length != 0 ? active.next("img") : $j('.BackgroundImageRotator img:first');
	
	active.addClass('last-active').removeClass('active');

	next.css({ opacity: 0.0 }).addClass('active').animate({ opacity: 1.0 }, 5000, function () {
        	active.removeClass('last-active');
        });
}

	/* If not IE6 */
	jQuery.each(jQuery.browser, function(i, val) {
		if(i !="mozilla" && jQuery.browser.version.substr(0,3)!="6.0"){
			jQuery.fn.center = function (absolute) {
				return this.each(function () {
					var t = jQuery(this);
					t.css({
						position:    absolute ? 'absolute' : 'fixed', 
						left:        '50%', 
						top:        '50%'
					}).css({
						marginLeft:    '-' + (t.outerWidth() / 2) + 'px', 
						marginTop:    '-' + (t.outerHeight() / 2) + 'px'
					});
			
					if (absolute) {
						t.css({
							marginTop:    parseInt(t.css('marginTop'), 10) + jQuery(window).scrollTop(), 
							marginLeft:    parseInt(t.css('marginLeft'), 10) + jQuery(window).scrollLeft()
						});
					}
							
							if((0 - (parseInt(t.css('marginLeft'),10) * 2)) + 20 > jQuery(window).width())
							{
								t.css({'marginLeft':'0', 'left':'0px'});
							}
							if((0 - (parseInt(t.css('marginTop'),10) * 2)) + 40 > jQuery(window).height())
							{
								t.css({'marginTop':'0', 'top':'20px'});
							}
				});
			};
		}
	 });
