var off
var pl
var pr

$(document).ready(function(){

	$('a[rel=external]').click(function(){
		window.open(this.href);
		return false;
	});


	// ------------- CUFON START
	var ca = [
		'#main .top .login span',
		'#content-holder .menu .element',
		'#content-holder .submenu .element',
		'#content-holder .subsubmenu .element',
		'#content-holder .ads .left .ad .desc .hs',
		'#content-holder .ads .left .ad .desc .hb',
		'#content-holder .content .more',
		'#foot .info .heads .h1',
		'#foot .info .heads .h2',
		'#foot .info .heads .h3',
		'#foot .info .content .c2 .subsubmit button',
		'#content-holder .content .stripe .bar span',
		'#content-holder .content .stripe .bar h2',
		'#content-holder .content .stripe .bar h3',
		'#content-holder .content .normal .oe .head',
		'#content-holder .content .decor .oe .head',
		'#content-holder .content .ss1 big',
		'#content-holder .content .ss2 big',
		'#content-holder .content .ss3 big',
		'#content-holder .content .accordion-list li .title .txt',
		'#content-holder .content .accordion-list li .title big',
		'#content-holder .content .plain-text .lh',
		'#content-holder .content .cch',
		'#content-holder .content .decor .pakiety-d-i h2',
		'#content-holder .content .decor .pakiety-d-i h3',
		'#content-holder .content .pakiety-ex',
		'#content-holder .content .pakiety-btn-order'
	];
	
	Cufon.replace(ca.join(','), {'fontFamily':'SegoeUI', hover:true});
	// ------------- CUFON END
	
	
	if($('#content-holder .submenu').length > 0)
	{
		off = $('#content-holder .submenu').position().left;
		pl = parseInt($('#content-holder .submenu .element').css('padding-left').replace('px', ''))
		pr = parseInt($('#content-holder .submenu .element').css('padding-right').replace('px', ''))
	}
	else
	{
		off = $('#content-holder .menu').position().left;
		pl = parseInt($('#content-holder .menu .element').css('padding-left').replace('px', ''))
		pr = parseInt($('#content-holder .menu .element').css('padding-right').replace('px', ''))
	}
	
	
	
	/*
	if($('#content-holder .submenu').length > 0)
	{
		//$('#content-holder .submenu .element').hover(function(){ animate_slider($(this)); })
	}
	else
	{
		//$('#content-holder .menu .element').hover(function(){ animate_slider($(this)); })
	}
	//*/
	if($('#map_canvas').length > 0) {initMap()}
	
	
	$('#content-holder .content .oe .infobox').mouseover(function(){
		
		var o = {width: 300, height: 155, left: 0}

		if($(this).hasClass('bottom')) {o = {width: 300, height: 155, left: 0, top: -137}}
		if($(this).hasClass('left')) {o.left = -282;}
		if($(this).hasClass('h230')) {o.height = 230;}
		if($(this).hasClass('h220')) {o.height = 220;}
		if($(this).hasClass('h190')) {o.height = 190;}
		
		$(this).parent().css('z-index', 40);
		$(this).animate(o, {duration: 'fast',queue: false, easing: 'linear', complete: function(){$(this).parent().css('z-index', 40)}});
	})
	
	$('#content-holder .content .oe .infobox').mouseout(function(){
		
		var bo = {width: 18, height: 18, left: 0}
		
		if($(this).hasClass('bottom')) {bo = {width: 18, height: 18, left: 0, top: 0}}
		
		$(this).animate(bo, {duration: 'fast',queue: false, easing: 'linear', complete: function(){$(this).parent().css('z-index', 1)}});
		
	})
	
	$('#content-holder .content .activator').mouseover(function(){
		$('#ex'+$(this).attr('id').substr(2,1)).mouseover();
	})
	$('#content-holder .content .activator').mouseout(function(){
		$('#ex'+$(this).attr('id').substr(2,1)).mouseout();
	})

	if($('.accordion-list').length > 0)
	{
		$('.accordion-list').accordion({ 
			header: 'div.title',  
			alwaysOpen: false,
			active: false,
			animated: 'easeslide', 
			autoheight: false
		});
	}
	
	setTimeout("delayAmnimate()",100);

	window.setTimeout(function() {
		$('.skype_pnh_container').html('');
		$('.skype_pnh_print_container').removeClass('skype_pnh_print_container');
	}, 1200);
	window.setTimeout(function() {
		$('.skype_pnh_container').html('');
		$('.skype_pnh_print_container').removeClass('skype_pnh_print_container');
	}, 2500);
	
	$('.inactive').click(function(){
		alert("Pakiet zostanie udostępniony już w wkrótce.");
		return false;
	})
	
	$('.input-error').click(function(){
		$(this).hide().siblings('input[type=text], input[type=password], textarea').focus();
	});

	$('input').keypress(function(){
		//console.log($(this).siblings('.input-error'))
		$(this).siblings('.input-error').hide();
	})

	//$('#content-holder .content .normal .oe .infobox .arrowSqare')
});

$(document).mousemove(function(e){
	
	if($('#content-holder .submenu').length > 0)
		var m = $('#content-holder .submenu');
	else
		m = $('#content-holder .menu');

	var mp = m.position();
	
	//if(!((e.pageX > mp.left && e.pageX < mp.left+m.width()) && (e.pageY > mp.top && e.pageY < mp.top+m.height())))
	
})

function delayAmnimate()
{
	if($('#content-holder .submenu').length > 0) {animate_slider($('#content-holder .submenu .current'))}
	else {animate_slider($('#content-holder .menu .current'))}
}

function animate_slider(elem, b)
{
		if(elem.css('width') != null)
		{
			var tw = parseInt(elem.css('width').replace('px', ''))+pl+pr
			var tx = parseInt(elem.position().left)-off+1;
			
			//if(b) tw += pl
			
			if(elem.hasClass('blue')) tw -= 8;
			
			$('#content-holder .single .slider').animate({
				width: tw,
				left: tx
			}, {duration: 'fast',queue: false, easing: 'linear'});

			$('#content-holder .single .pointer').animate({
				left: tx+(tw/2)-9
			}, {duration: 'fast',queue: false, easing: 'linear'});
		}
		else
		{
			$('#content-holder .undermenu .pointer').hide();
		}
}

function initMap() {
	var myLatlng = new google.maps.LatLng(50.101575,18.22987);

	var myOptions = {
		zoom: 15,
		center: myLatlng,
		mapTypeControl: false,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	}
	
	var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	
	new google.maps.Marker({
		map: map,
		position: myLatlng,
	});
}

