BrowserDetect.init();

if (BrowserDetect.browser == "Safari") {
	document.write("<link type='text/css' rel='stylesheet' href='css/safari.css' />");
}
if (BrowserDetect.OS == "Mac" && BrowserDetect.browser == "Firefox" && BrowserDetect.version == "2") {
	document.write("<link type='text/css' rel='stylesheet' href='css/ff-mac.css' />");
} else if (BrowserDetect.OS == "Mac" && BrowserDetect.browser == "Firefox" && BrowserDetect.version == "3.6") {
	document.write("<link type='text/css' rel='stylesheet' href='css/ff3-mac.css' />");
} else if (BrowserDetect.OS == "Mac" && BrowserDetect.browser == "Firefox" && BrowserDetect.version >= "5") {
	document.write("<link type='text/css' rel='stylesheet' href='css/ff5-mac.css' />");
}

if (BrowserDetect.OS == "Mac" && BrowserDetect.browser == "Chrome") {
	document.write("<link type='text/css' rel='stylesheet' href='css/chrome-mac.css' />");
} else if (BrowserDetect.OS == "Win" && BrowserDetect.browser == "Chrome") {
	document.write("<link type='text/css' rel='stylesheet' href='css/chrome-win.css' />");
}

// js text replacement
Cufon.replace('.content-left h1');


$(document).ready(function(){	
						   
	// init dropdown menu
	$('ul#navigation').superfish();
	
	if ((BrowserDetect.browser != "Explorer") || (BrowserDetect.browser == "Explorer" && BrowserDetect.version != 8)) {
		$('ul#navigation li ul').css('opacity',0.95);
	}
		
	// page url taken from the last '/ '
	var path = location.pathname.substring(location.pathname.lastIndexOf("/") + 1);
	var currLink = $('ul#navigation li a[href$="' + path + '"]');
	
	if (path == "") {
		// highlight home tab
		$('ul#navigation li a[href$="index.html"]').addClass('active');	
	} else if ((path == "acoustic_residential_house.html") || (path == "acoustic_residential_apartment.html")) {
		// highlight acoustic tab
		$('ul#navigation li a.header:eq(3)').addClass('active');	
	} else {	
		// add active class to current page link
		$(currLink).addClass('active');	
	}
	
	// if a dropdown link is the currLink
	if ($('ul#navigation li ul li a').hasClass('active')){
		
		var dropdown = $('ul#navigation li ul li a.active');
		var parent = $(dropdown).parents('li').children('a.header');
		
		// highlight the parent
		$(currLink).removeClass('active');
		$(parent).addClass('active');
	}
	
	// slideshow
	if ($('body').hasClass('home')) {
		$('#slideshow').preloadSlides({
			images: ["<li><img src='images/slideshow/home/slide3.jpg' alt='thermally efficient cool' width='886' height='251' /></li>", 
				   "<li><img src='images/slideshow/home/slide4.jpg' alt='thermally efficient warm' width='886' height='251' /></li>",
				   "<li><img src='images/slideshow/home/slide5.jpg' alt='acoustically efficient Sound' width='886' height='251' /></li>",
				   "<li><img src='images/slideshow/home/slide6.jpg' alt='low irritant aafe' width='886' height='251' /></li>"
			],		
			imageLoadCallback: test,
			callback: startCycle				
		});
	} else if ($('body').hasClass('contact')) {
		// do nothing
	} else {
		startCycle();
	}

	function startCycle() {
		$('#slideshow ul').cycle({
			speed: "slow",
			timeout: 3000
		});
	}
	
	function test(currentSlide){
		//console.log(currentSlide);	
	}
	
	if($('body').hasClass('home')){
	
		// hide video image (this is displayed if user doesn't have javascript)
		$('.content-right img').hide();
		// append video player markup
		$('.content-right').append('<div id="video-container" />');
		
		// JWPlayer
		var flashvars = {
			dock: 'false',
			file: '../video/8136-1_454x256_Polymax_video_home_page.mp4',
			image:'../images/8136-1_454x256_Polymax_video_backup.jpg',
			autostart: 'true',
			stretching: 'fill',
			controlbar: 'bottom',
			stretching: 'none'
		};
		var params = {
			allowscriptaccess: 'always',
			allowfullscreen: 'true',
			wmode: 'transparent'
		};
		swfobject.embedSWF('../swf/player.swf', 'video-container', '454', '280', '9', null, flashvars, params);
	}
	
});
