/* IE6 flicker fix
-------------------------------------------------- */
try { document.execCommand("BackgroundImageCache", false, true); } catch(err){}

/* Init */

$(document).ready(function() {
	$('.ihasahover').hover(function(){ $(this).addClass('hover'); },function(){ $(this).removeClass('hover'); });
	$('.noautocomplete').attr('autocomplete', 'off');
});

/* Tabs switcher */

function showTab(ref,set){
	$('#'+set+' > LI > A').each(function(i,a){
		$(a).removeClass('active');
		$($(a).attr('href')).addClass('hidden');
	});
	$(ref).addClass('active');
	$($(ref).attr('href')).fadeIn(10).removeClass('hidden').css({display: ''});
	return false;
}

/* Loader */
var indexBoxes = {
	status: {},
	init: function() {
		// Avatavate elementide vaikestaatuste määramine
		$('.quik-news a').each(function(){
			indexBoxes.status[$(this).attr('rel')] = false;
		});
		$('.quik-news a').click(function(){
			indexBoxes.switchBox($(this).attr('rel'));
		});
	},
	switchBox: function(currentBox) {
		// Avame või sulgeme valitud elemendi vastavalt staatusele
		if (indexBoxes.status[currentBox] == false) {
			indexBoxes.status[currentBox] = true;
			$('.' + currentBox).removeClass('hidden');
		} else {
			indexBoxes.status[currentBox] = false;
			$('.' + currentBox).addClass('hidden');
		}
		// Käime ülejäänud elemendid läbi ja sulgeme kui pole vajutatud element
		$.each(indexBoxes.status, function(k, v) {
			if (k != currentBox && v == true) {
				indexBoxes.status[k] = false;
				$('.' + k).addClass('hidden');
			}
		});
	}
};

$(document).ready(function() {
	$('#info').click(function(){
		if ($('#info2').hasClass('hidden')) {
			$('#info2').css({
				top: $('#info').offset().top + $('#info').outerHeight() + 'px',
				left: $('#info').offset().left + 'px'
			});
			$('#info DIV.info03').addClass('hidden');
			$('#info DIV.info05').removeClass('hidden');
			$('#info2').slideDown().removeClass('hidden').addClass('opened');
		} else {
			$('#info2 DIV.info04').click();
		}
	});
	$(window).resize(function(){
		$('#info2')[0].style.top = $('#info').offset().top + $('#info').outerHeight() + 'px';
		$('#info2')[0].style.left = $('#info').offset().left + 'px';
	});

	$('#info2 DIV.info04').click(function(){
		if ($('#info2').hasClass('opened')) {
			$('#info2').slideUp(function(){
				$('#info DIV.info03').removeClass('hidden');
				$('#info DIV.info05').addClass('hidden');
			}).removeClass('opened').addClass('hidden');
		}
	});

	// Index boxes
	indexBoxes.init();
});

$(document).ready(function() {

});

/* Front map elements */

var isIE7 = false;
//onload init
$(function() {
	
	function show(elem){
		if(isIE7){
			$("#"+elem).show();
		} else {
			$("#"+elem).stop().css({'opacity':'0','display':'block'}).animate({'opacity':'1'}); 
		}
	}
	
	function hide(elem){
		if(isIE7){
			$("#"+elem).hide();	
		} else {
			$("#"+elem).fadeOut();
		}
	}
	
	$('#map area').mouseover(function(){
    	var id = $(this).attr('id').replace('_area','');
		show(id);
    }).mouseout(function(){
		var id = $(this).attr('id').replace('_area','');
		hide(id);
	});

});

/* Switch news content */
$(document).ready(function() {
	$('P.heading.exp').each(function(i,a){
		$('A', a).click(function(){
			if($(this).hasClass('type02')){
				$(this).removeClass('type02');
				$($('A', a).attr('href')).addClass('hidden');
			} else {
				$(this).addClass('type02');
				$($('A', a).attr('href')).removeClass('hidden');
			}
			return false;
		});
		if(!$('A', a).hasClass('type02')){
			$($('A', a).attr('href')).addClass('hidden');
		}
	});
});