$(function() {

	$('#faktura').click(function(){

		var status = $(this).attr('checked');

		if(status !== false){

			$('.box #registration ul .hide.fkt').addClass('active').slideDown('slow',function(){$(this).removeClass('hide');});

		}		

		if(status === false){

			$('.box #registration ul .active.fkt').removeClass('active').slideUp('slow',function(){$(this).addClass('hide');});

		}

	});
	
	$('#six_seminars').click(function(){
		var status = $(this).attr('checked');

		if(status !== false){
			$('.box #registration ul li#seminars_text').addClass('active').slideDown('slow',function(){$(this).removeClass('hide');});
		}		
		
		if(status === false){
			$('.box #registration ul li#seminars_text').removeClass('active').slideUp('slow',function(){$(this).addClass('hide');});
		}				
	});

	$('#popup_btn').hover(function(){$('#popup_wrapper').fadeIn('fast');},function(){$('#popup_wrapper').fadeOut('fast');});  

	

	$("a[id^='big_image']").click(function(){

		$('.pretty:eq(0)').trigger('click');

		return false;

	});

	

	 $(".pretty").prettyPhoto();

	// CUSTOM SELECT

	

	$('#contact_form').bind('click mouseleave',function(e){

		if(e.target.id=='selected' || e.target.id=='subject_selector'){

			return false;

		}

		

		$('#subject_selector li').fadeOut(400).attr('class', 'hide');

		$('#subject_selector').css('display','none');

	});	

	

	$('.box').bind('click mouseleave',function(e){

		if(e.target.id=='choise_year' || e.target.id=='year_select'){

			return false;

		}

		

		$('#year_select li').fadeOut(400).attr('class', 'hide');

		$('#year_select').css('display','none');

	});	

	

	$('.box').bind('click mouseleave',function(e){

		if(e.target.id=='choise_payment' || e.target.id=='payment_select'){

			return false;

		}

		

		$('#payment_select li').fadeOut(400).attr('class', 'hide');

		$('#payment_select').css('display','none');

	});	

	

	$('.box').bind('click mouseleave',function(e){

		if(e.target.id=='mounth' || e.target.id=='mounth_select'){

			return false;

		}

		

		$('#mounth_select li').fadeOut(400).attr('class', 'hide');

		$('#mounth_select').css('display','none');

	});

	

	custom_select('#payment_select','#payment_select li','#choise_payment','#payment_input');

	custom_select('#year_select','#year_select li','#choise_year','#year_input');

	custom_select('#mounth_select','#mounth_select li','#mounth','#mounth_input');

	custom_select('#subject_selector','#subject_selector li','#selected','#subject_input');

	

	function custom_select(master_selector,selector,selected,hidden){

		$(selected).click(function(){

			$(selector).each(function() {

				$(master_selector).css('display','block');

				$(selector).fadeIn(400).removeAttr('class');

			});

			$(selector).click(function (){

				var val = $(this).attr('id');

				$(selected).text($(this).text());

				$(hidden).val(val);

				$(selector).each(function(){

					$(this).fadeOut(400).attr('class', 'hide');

					$(master_selector).css('display','none');

				});

			});

		});

		$(selector).hover(function(){

			$(this).css('background','#ccc');

		},function(){

			$(selector).css('background','none');

		});

	}

	

	// END

	

	// CONTACTS

	

	$('#contact_form form ul li input').click(function(){

		if ($(this).val() == $(this).attr('class')){

			$(this).val('');

		}

	});

	$('#contact_form form ul li textarea').click(function(){

		$(this).text('');

	});

	

	$('#contact_form form ul li input').focusout(function() {

		var default_value = $(this).attr('class');

		if ($(this).val() == ""){

			$(this).val(default_value);

		}

	});		

	

	$('#contact_form form ul li textarea').focusout(function() {

		var default_value = $(this).attr('class');

		if ($(this).text() == ""){

			$(this).text(default_value);

		}

	});	

	

	/////

	

	// REGISTRATION

	

	$('#registration ul li fieldset input').click(function(){

		if ($(this).val() == $(this).attr('class')){

			$(this).val('');

		}

	});

	

	$('#registration ul li fieldset textarea').click(function(){

		$(this).text('');

	});

	

	$('#registration ul li fieldset input').focusout(function() {

		var default_value = $(this).attr('class');

		if ($(this).val() == ""){

			$(this).val(default_value);

		}

	});		

	

	$('#registration ul li fieldset textarea').focusout(function() {

		var default_value = $(this).attr('class');

		if ($(this).text() == ""){

			$(this).text(default_value);

		}

	});	

	

	/////

	$('#flash_messages').each(function(){

		$(this).css('display', 'none');

		$(this).css('opacity', 0.65);

		$(this).fadeIn('slow');

		$('.close', $(this)).click(function(){ $($(this).parents('div')[0]).fadeOut(function(){ $(this).remove(); }); });

	});

});


