var LumixAward = function () {
	
	function init() {
		var IE6 = false;
		jQuery.each(jQuery.browser, function(i, val) {
											 
			if (i=="msie" && jQuery.browser.version.substr(0,3)=="6.0") IE6 = true;
		});
		
		if (!IE6) $('#login-inpage-link').click(LumixAward.showLogin);
		else LumixAward.initIE6();
	}
	
	function initIE6()
	{
		/* PNG fix */
		if (jQuery.fn.pngFix) $(document).pngFix();
	}
	
	
	function showLogin() {
		
		if ($('#login-inpage').css('display') == 'none') {
			
			$('#login-inpage').show().find('#login-close').one('click', LumixAward.hideLogin);
		}
		else LumixAward.hideLogin();
		
		return false;
	}
	
	
	function hideLogin() {
		
		$('#login-inpage').hide();
		
		return false;
	}
	
	
	function changeLanguage() {
		
		$('#country-select').change(function() {
			
			var lang = $('#country-select option:selected').val();
			
			if (lang != '') window.location = 'default.aspx?lang=' + lang;
		});
	}
	
	
	function inPageScroll() {
		
		var locationPath = LumixAward.filterPath(location.pathname);
		
		$('a.in-page').each(function() {
			
			var thisPath = LumixAward.filterPath(this.pathname) || locationPath;
			
			if (locationPath == thisPath && (location.hostname == this.hostname || !this.hostname)
				&& this.hash.replace(/#/,'') ) {
				
				var $target = $(this.hash);
				var target = this.hash;
				
				if (target) {
					var targetOffset = $target.offset().top;
					$(this).click(function(e) {
										   
						e.preventDefault();
						$('html, body').animate({scrollTop: targetOffset}, 800, function(){ location.hash = target; });
					});
				}
			}
		});
	}
	
	
	function filterPath(string) {
	
		return string
			.replace(/^\//,'')
			.replace(/(index|default).[a-zA-Z]{3,4}$/,'')
			.replace(/\/$/,'');
	}
	
	function externalLinks() {
		if (!document.getElementsByTagName) 
		{
			return;
		}
		var anchors = document.getElementsByTagName("a");
		for (var i=0; i<anchors.length; i++) 
		{
			var anchor = anchors[i];
			if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
			{
				anchor.target = "_blank";
			}
		}
	}	
	
	return {
	
		init: init,
		initIE6: initIE6,
		showLogin: showLogin,
		hideLogin: hideLogin,
		changeLanguage: changeLanguage,
		inPageScroll: inPageScroll,
		filterPath: filterPath,
		externalLinks: externalLinks
	};

}();

$(document).ready(function() {

	LumixAward.init();
	LumixAward.changeLanguage();
	LumixAward.inPageScroll();
	LumixAward.externalLinks();
});
