var timeout    = 800;
var closetimer = 0;
var ddmenuitem = 0;
var ddmenubutton = 0;

function jsddm_open()
{
	jsddm_canceltimer();
	if($(this).find('ul').css('display') == 'block')
	{
		return;
	}
	
	jsddm_close();
	ddmenuitem = $(this).find('ul').css('display', 'block');
	$(this).addClass('active-option');
	ddmenubutton = $(this);
	//if($.browser.msie) return;
	
	if(!$.browser.msie)
	{
		ddmenuitem.css('opacity', '0');
		//ddmenuitem.css('left', '30px');
		
		ddmenuitem.animate(
		{
			opacity: 1
			//left: '0px'
		}, 150, 'swing', function(){});
	}	
	else
	{
		ddmenuitem.show();
	}
}

function jsddm_close()
{
	if(ddmenuitem) ddmenuitem.css('display', 'none');
	if(ddmenubutton) ddmenubutton.removeClass('active-option');
		
}

function jsddm_timer()
{  closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{  
	if(closetimer)
	{  
	  window.clearTimeout(closetimer);
      closetimer = null;
	}
}

function getRidOfFlash()
{
	$('.flashContainer').css('display', 'none');
	$('.flashContainer').parent().css('display', 'none');
}

function flashLoaded()
{
	$('.flashContainer').css('background', 'none');
}

function resizeFlashContainer()
{
	$('.flashContainer').width(1);
	$('.flashContainer').height(1);
	$('.flashContainer').width($(document).width());
	$('.flashContainer').height($(document).height());
	
}

$(document).ready(function()
{  	
	
	$('.head_right_notop .menu > li').bind('mouseover', jsddm_open);
	$('.head_right_notop .menu > li').bind('mouseout',  jsddm_timer);
	
	$('#search-go').click(function (event){
		if($(this).prev().val()== "")
			return false;
		return true;
	});
	
	$('#search-field').click(function(event) {
		if($(this).val()=='Search')
			$(this).val('');
	});
	
	$('#search-field').blur(function(event) {
		if($(this).val()=='')
			$(this).val('Search');
	});
	
	$('.box1_zew').click(function(){
		window.open($(this).find('.box1').attr('alt') ,'_self');
	});
	
	$('.box2_zew').click(function(){
		window.open($(this).find('.box2').attr('alt') ,'_self');
	});
	
	$('.box3_zew').click(function(){
		window.open($(this).find('.box3').attr('alt') ,'_self');
	});
	
	
	$('.formular #submit').click(function(event)
	{
		var a = ['surname', 'given_name', 'title',
		'email', 
		'message',
		'security_code',
		'course',
		'first-name',
		'last-name',
		'company',
		'address',
		'city',
		'post-code',
		'country',
		'telephone',
		'name',
		'scenario'];
		var ok=true;
		
		if($('#privacy').attr('checked'))
		{
			$('#privacy-desc').removeClass('alertclass');
		}else{
			$('#privacy-desc').addClass('alertclass');
			ok = false;
		}
		
		
		var i = a.length;
		while(i--)
		{
			if($('#'+a[i]).val()=="")
			{
				$('#'+a[i]).addClass('alertclass');
				$('#'+a[i]).change(function() {
					$(this).removeClass('alertclass');
				});
				ok = false;
			}
		}
		
		
		if(ok)
			return true;
		else
		{
			return false;
		}
	});
	
	
	$('.flake').hover(function() {
		$(this).addClass('flakeHover');
	}, function () {
		$(this).removeClass('flakeHover');
	});
	$('.flake').click(function(e) {
		window.location = $(this).find('a').attr('href');
	});
	
	
	
	
	$('#submit_gt').click(function(event)
	{
		var ok=true;
		$('.required').each(function(i) {
			
			if($(this).val()=="" || $(this).val()=="0")
			{
				$(this).addClass('alertclass');
				$(this).change(function() {
					$(this).removeClass('alertclass');
				});
				ok = false;
			}
		 
		});
		
		var name_buf = "";
		var p_ok=true;
		var name;
		$('.required_radio').each(function(i) {
			
			name = $(this).attr('name');
			
			if(name_buf !="" && name != name_buf && p_ok == false)
			{
				selectThis(name);
				p_ok = false;
				ok = false;
			}
			name_buf = name;
			if($(this).attr('checked')==true)
				p_ok = true;
		 
		});
		
		if(p_ok == false)
		{
			selectThis(name);
			ok = false;
		}
		
		function selectThis(_name)
		{
			
			$('#'+_name+"_cont").addClass('alertclass');
			$('#'+_name+"_cont").change(function() {
				$('#'+_name+"_cont").removeClass('alertclass');
			});
		}
		
		
		
		if(ok)
		{
			return true;
		}
		else
		{
			
			$('#form_gt_alert').css('visibility', 'visible');
			return false;
		}
	});
	
	
	
	// set width of the bottom menu
	
	var d = 2;
	
	$(".menu2").find("li").each(function(i) {
     d += $(this).width() + 3;
	 
   });
	//$(".menu2").css("width", d+"px");
	
	
	//$("#left-box .thumbnail a").lightBox(); // Select all links that contains lightbox in the attribute rel
	//$(".lightbox-image a").lightBox(); // Select all links that contains lightbox in the attribute rel
	$('a.lightbox').each(function() {
		$(this).attr('rel', 'group1');
		if($(this).attr('name')) $(this).attr('title', $(this).attr('name'));
	});
	$('.lightbox-image a, a.lightbox').colorbox();
	
	$.dpText = {
		TEXT_PREV_YEAR		:	'Poprzedni rok',
		TEXT_PREV_MONTH		:	'Poprzedni miesiąc',
		TEXT_NEXT_YEAR		:	'Następny rok',
		TEXT_NEXT_MONTH		:	'Następny miesiąc',
		TEXT_CLOSE			:	'Zamknij',
		TEXT_CHOOSE_DATE	:	'Wybierz datę'
	}
	
	
	$('.datePick').datePicker({startDate:'01/01/1900'});
	
	
	/* multicolor anchors */
	var colors = new Array();
	colors[0] = "#fe7e00";
	colors[1] = "#73c300";
	colors[2] = "purple";
	$("#content p a").each(function (index) {
		$(this).css("color",colors[Math.floor(Math.random()*colors.length)]);
	});
	$("#content p a").hover(function () {
		$(this).css("color","");
	}, function () {
		$(this).css("color",colors[Math.floor(Math.random()*colors.length)]);
	});
	
	
	
	var colorsOffer = new Array();
	colorsOffer.push("#fe7e00", "#73c300", "purple", "#e80d55", "#830de8", "ff0000", "cc0000", "#ffcc10", "#58ff10", "#0060ff", "#b5e900");
	$(".offer-quick ul li").each(function (index) {
		//$(this).css("color",colorsOffer[Math.floor(Math.random()*colorsOffer.length)]);
	});
	var buf = "";
	$(".offer-quick ul li, .offer-static ul li").hover(function () {
		buf = $(this).css("color");
		$(this).css("color",colorsOffer[Math.floor(Math.random()*colorsOffer.length)]);
		$(this).addClass("offerOptionHover");
	}, function () {
		$(this).css("color",buf);
		$(this).removeClass("offerOptionHover");
	});
	
	$('.offer-more').css("display", "none");
	//$('#www').css("display", "none");
	//$('#www').next().css("display", "block");
	//$('#www').prev().children().children().toggle();
	
	$('.offer-quick').click(function(event) {
		var _this = this;
	
		$(this).slideUp(200);
		setTimeout(function () {$(_this).next().slideDown(200);}, 300);
		
		// zwin
		$(this).prev().children().children().toggle();
	});
	
	$('.an-offer .more-button-container').click(function(event) {
		event.preventDefault();
		var _this = this;
		if($(this).next().css("display") !="none")
		{
			$(this).next().slideToggle(200);
			setTimeout(function () {$(_this).next().next().slideToggle(200);}, 300);
		} else {
			$(this).next().next().slideToggle(200);
			setTimeout(function () {$(_this).next().slideToggle(200);}, 300);
		}
		
		$(this).children().children().toggle();
		
	});
	
	
	
	
	
	$('.faq-link').click(function(e){
		e.preventDefault();
		$(this).next().slideToggle();
		
	});
	
	
	$('.read-more').html('<span>Read-more</span>');
	

});

document.onclick = jsddm_close;





