
var Common = {

	init: function(base_path, theme, lang, template) {

		this.base_path = base_path;
		this.theme = theme;
		this.lang = lang;
		this.template = template;
		
		$(function() {
			if(Common.template == 'default') {
				Common.initFrontSwf();
			} else {
				Common.initMainMenu();
				Common.initMenu();
				Common.search();
			}
		});
	},
	setLocation: function(url) {
		document.location.href = url;
	},
	roundFloatNumber: function(number, precision) {
		if(parseFloat(number)) {
			return Math.round(number * Math.pow(10, precision)) / Math.pow(10, precision);
		}
		return 0;
	},
	initFrontSwf: function() {
		swfobject.embedSWF(Common.base_path + "public/" + Common.theme + "/intro.swf", "mainElement", "800", "600", "10", "", false, {menu:"false"});
	},
	initMainMenu: function() {
		$('#mainMenu li').each(function() {
			if($(this).attr('id') == 'activeMainElement') {
				$('img', this).attr('src', $('img', this).attr('src').replace(/.png/, 'Active.png'));
			} else {
				$(this).mouseover(function() {
					$('img', this).attr('src', $('img', this).attr('src').replace(/.png/, 'Active.png'));
				}).mouseout(function() {
					$('img', this).attr('src', $('img', this).attr('src').replace(/Active.png/, '.png'));
				});
			}
		});
	},
	initMenu: function() {
		$('#menu li').mouseover(function() {
			$('a', this).first().css('color', '#8cb7f2');
			$('span', this).show();
		}).mouseout(function() {
			$('a', this).first().css('color', '');
			$('span', this).hide();
		});
	},
	search: function() {
		$('#searchBlock #searchButton').click(function() {
			var query = jQuery.trim($('#searchBlock #query').val());
			if(query != '') {
				document.location.href = Common.base_path + '' + Common.lang + '/search?query=' + query;
			}
		});
	}
};
