/* IE6 flicker fix */

try { document.execCommand("BackgroundImageCache", false, true); } catch(err){}

/* Make a working ie6 detection for jquery */

$.browser.msie6 = $.browser.msie && /MSIE 6\.0/i.test(window.navigator.userAgent) && !/MSIE 7\.0/i.test(window.navigator.userAgent);

var now = new Date();



$(document).ready(function(){

		/* ----------------------------
			ENTERTAINMENT.EE SYSTEM JS
		------------------------------*/
		$.post('../../kangavalik.php',function(data){
			$('#enter_system_slider').html(data);								
											});
		var move_by = 630+'px';
		var cur_frame = 1;
	
		$('.enter_system_arrow_left').click(function(){
				if ( cur_frame != 1 && cur_frame > 1 )
				   {
						$('#enter_system_slider').animate({left: '+='+move_by});  
						--cur_frame;
				   }									 
													 });
		$('.enter_system_arrow_right').live('click',function(){	
				var click_count = $('#enter_system_click_count').text();														
				if ( cur_frame != click_count )
				   {
						$('#enter_system_slider').animate({left: '-='+move_by});  
						++cur_frame;
				   }
													 });
		
		
	// remove lang 
	$('#langselect').hide();
	if (top === self){ $('#langselect').show(); }
	
	$('#langselect li a').click(function(){
			if($(this).attr('class') == 'fi'){
				window.location = 'http://www.telttamaailma.fi/';
				return false;
			}
										 });
	
	var query = window.location.toString(); 
	var splited = query.split("/");
	if ( splited[3] == 'ru' )
	{
	//c = $('#menu01 LI').size();
	//w = 920/c;
	$('#menu01 LI a').width('62px');
	$('.c1 a').width('43px');
	$('.c8 a').width('83px');
	$('.c9 a').width('73px');
	$('.c2 a span').css({ 'position' : 'relative' ,'left' : '-10px'});
	$('.c6 a span').css({ 'position' : 'relative' ,'left' : '-15px'});
	$('.c9 a span').css({ 'position' : 'relative' ,'left' : '10px'});
	$('.c6 a span').css({ 'position' : 'relative' ,'left' : '10px'});
 	//css fixes for menu
	/*$('#menu01 LI').css('width' , '73px');
	$('#menu01 LI').css('padding-right' , '5px');
	$('#menu01 LI').css('padding-left' , '5px');*/
	//$('#menu01 LI').css('background' , 'none');
	$('#menu01 LI a').css('text-align' , 'center');
	$('#menu01 A ').css('top','-5px');
	}
	

	// Add nice tooltips

	$('.showtooltip').tooltip();

	// Date fields calendar

	$('INPUT.pickdate').each(function(a,b){

		$(this).DatePicker({

			current: $(b).val(),

			date: $(b).val(),

			format: 'd.m.Y',

			calendars: 1,

			mode: 'single',

			position: 'right',

			setmargin: '-10px 0 0 30px',

			onShow: function(){ $(this).focus(); },

			//onRender: function(date){ return { disabled: (date.valueOf() < now.valueOf()) }},

			onChange: function(formated, dates) { $($(this).data('datepicker')['el']).val(formated).DatePickerHide().focus(); },

			start: 0

		});

	}).after(' <img src="' + js_site_url + 'img/ico_calendar.gif" alt="" onclick="$(this).prev(\'INPUT.pickdate\').DatePickerShow(); return false;" class="dateico" />');

});



/* Tooltips

 * $LastChangedDate: 2010.01.18

 * by Exact

 */



(function($){ $.fn.tooltip = function(){

	return this.each(function(index) {

		var $this = $(this);

		$tooltip=$("#tooltip");

		if($tooltip.length == 0){

			var tmp = '<div id="tooltip"><div id="tooltip-start"><span class="a"></span><span class="c"></span><span class="b"></span><span class="d"></span></div>';

			tmp += '<div id="tooltip-body">';

			tmp += '	<span class="content-a"></span>';

			tmp += '	<div class="content-b"><div id="tooltip-inner" class="w100p content"></div></div>';

			tmp += '	<span class="content-c"></span>';

			tmp += '</div>';

			tmp += '<div id="tooltip-ending"><span class="a"></span><span class="c"></span><span class="b"></span><span class="d"></span></div></div>';

			$tooltip = $(tmp);

			$('body').append($tooltip);

		}

		function displayTooltip(e){

			if( $this.attr("title") == "" && $this.attr("alt") == ''){ return; }

			$tooltip.removeClass($tooltip.attr("class"));

			$tooltip.data("title",$this.attr("title"));

			$tooltip.data("alt",$this.attr("alt"));

			$this.attr("title","");

			$this.attr("alt","");

			$('#tooltip-inner').html($tooltip.data("title"));

			var href=$this.attr("lang");



			fit = $('BODY').outerWidth() - $this.offset().left - $tooltip.outerWidth() - 15;

			viewport = window.innerWidth ? window.innerWidth : $(window).width();

			if( ($this.offset().left + $tooltip.outerWidth() - $(document).scrollLeft() - 15) > viewport){

				$tooltip.css("left", $this.offset().left + $this.outerWidth() - $tooltip.outerWidth() + 25 + 'px');

				$('#tooltip-ending SPAN.d').css({ left: $tooltip.outerWidth() - 42 + 'px' });

			} else if( fit < 0 ){

				$tooltip.css("left", $this.offset().left + fit + 'px');

				$('#tooltip-ending SPAN.d').css({ left: 0 - fit + 'px' });

			} else {

				$tooltip.css("left", $this.offset().left + 'px');

				$('#tooltip-ending SPAN.d').css({ left: '0' });

			}

			$tooltip.css("top", $this.offset().top - $tooltip.outerHeight() + 'px');

		}

		$this.mouseover( function(e){ displayTooltip(e); });

		$this.mouseout(function(e){

			$this.attr("title",$tooltip.data("title"));

			$this.attr("alt",$tooltip.data("alt"));

			$tooltip.css({left: '-1000px', top: '-1000px'});

		});

		$this.click(function(e){ e.preventDefault(); });

	});



}})(jQuery);



/* Open mapwindow */



var popwin;

function openAdvPopup(url,w,h,ext){

	var str = "height="+h+",innerHeight="+h+",width="+w+",innerWidth="+w;

	if(ext){

		str += ext

	} else {

		str += ',scrollbars=yes,menubar=no,resizable=yes,toolbar=no,location=no,status=no';

	}

	if (window.screen) {

		var ah = screen.availHeight - 30;

		var aw = screen.availWidth - 10;



		var xc = (aw - w) / 2;

		var yc = (ah - h) / 2;



		str += ",left=" + xc + ",screenX=" + xc;

		str += ",top=" + yc + ",screenY=" + yc;

	}

	popwin = window.open(url,'',str);

	return false;

}



/**

 * jQuery.ScrollTo - Easy element scrolling using jQuery.

 * Copyright (c) 2007-2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com

 * Dual licensed under MIT and GPL.

 * Date: 9/11/2008

 * @author Ariel Flesler

 * @version 1.4

 *

 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html

 */

;(function(h){var m=h.scrollTo=function(b,c,g){h(window).scrollTo(b,c,g)};m.defaults={axis:'y',duration:1};m.window=function(b){return h(window).scrollable()};h.fn.scrollable=function(){return this.map(function(){var b=this.parentWindow||this.defaultView,c=this.nodeName=='#document'?b.frameElement||b:this,g=c.contentDocument||(c.contentWindow||c).document,i=c.setInterval;return c.nodeName=='IFRAME'||i&&h.browser.safari?g.body:i?g.documentElement:this})};h.fn.scrollTo=function(r,j,a){if(typeof j=='object'){a=j;j=0}if(typeof a=='function')a={onAfter:a};a=h.extend({},m.defaults,a);j=j||a.speed||a.duration;a.queue=a.queue&&a.axis.length>1;if(a.queue)j/=2;a.offset=n(a.offset);a.over=n(a.over);return this.scrollable().each(function(){var k=this,o=h(k),d=r,l,e={},p=o.is('html,body');switch(typeof d){case'number':case'string':if(/^([+-]=)?\d+(px)?$/.test(d)){d=n(d);break}d=h(d,this);case'object':if(d.is||d.style)l=(d=h(d)).offset()}h.each(a.axis.split(''),function(b,c){var g=c=='x'?'Left':'Top',i=g.toLowerCase(),f='scroll'+g,s=k[f],t=c=='x'?'Width':'Height',v=t.toLowerCase();if(l){e[f]=l[i]+(p?0:s-o.offset()[i]);if(a.margin){e[f]-=parseInt(d.css('margin'+g))||0;e[f]-=parseInt(d.css('border'+g+'Width'))||0}e[f]+=a.offset[i]||0;if(a.over[i])e[f]+=d[v]()*a.over[i]}else e[f]=d[i];if(/^\d+$/.test(e[f]))e[f]=e[f]<=0?0:Math.min(e[f],u(t));if(!b&&a.queue){if(s!=e[f])q(a.onAfterFirst);delete e[f]}});q(a.onAfter);function q(b){o.animate(e,j,a.easing,b&&function(){b.call(this,r,a)})};function u(b){var c='scroll'+b,g=k.ownerDocument;return p?Math.max(g.documentElement[c],g.body[c]):k[c]}}).end()};function n(b){return typeof b=='object'?b:{top:b,left:b}}})(jQuery);


