jQuery(function() {
    jQuery('.tipn').tipsy({gravity: 'n', html: true});
    jQuery('.tips').tipsy({gravity: 's', html: true});
    jQuery('.tipe').tipsy({gravity: 'e', html: true});
    jQuery('.tipw').tipsy({gravity: 'w', html: true});
    jQuery('.tipnw').tipsy({gravity: 'nw', html: true});
    jQuery('.tipne').tipsy({gravity: 'ne', html: true});
    jQuery('.tipsw').tipsy({gravity: 'sw', html: true});
    jQuery('.tipse').tipsy({gravity: 'se', html: true});
});
function changeTab(tab, list){
	jQuery('.'+list+'content').addClass('hidden');
	jQuery('#content'+tab).removeClass('hidden');
	jQuery('.'+list+' li a').removeClass('active');
	jQuery('.tab'+tab+' a').addClass('active');
}

function toggleStandars (id_parking, section){
	if(jQuery('#standard'+section+id_parking).hasClass('hidden')){
		jQuery('.tip'+id_parking+'s').tipsy({gravity: 's', html: true});

		jQuery('#standard'+section+id_parking).removeClass('hidden');
		jQuery('#rozwin'+section+id_parking).addClass('hidden');
	}else{
		jQuery('#standard'+section+id_parking).addClass('hidden');
		jQuery('#rozwin'+section+id_parking).removeClass('hidden');

	}
}

function confirmopinion(id_opinion, value)
{
	var url = "/parking/confirmopinion";
	var pars = "id_opinion="+id_opinion+"&value="+value;
	jQuery.post(url, pars, function(data){
		if(data =='false'){
			alert('Na opinię można głosować tylko raz.');
		}else{
			jQuery('#opinionreplycontent'+id_opinion).html(data);
		}
	}
	);
}

function sendloginformation(id)
{
	jQuery('#sendloginformationbox .ajaxpreloader').removeClass('hidden');
	var url = "/parking/sendloginformation";
	var pars = "id="+id;
	jQuery.post(url, pars, function(data){
		jQuery('#sendloginformationbox .ajaxpreloader').addClass('hidden');
		if(data =='false'){
			alert('Aby zapobiec nadużyciom. E-mail z informacją o logowaniu można wysłać raz na godzinę.');
		}else{
			jQuery('#sendloginformationbox').html(data);
		}

	}
	);
}


function checkrateaddbox()
{
	tafocus(jQuery('.rateaddbox textarea'), 'Komentarz do oceny');
	if(jQuery('.rateaddbox textarea').val() == ''){
		alert('Proszę wpisać komentarz do oceny');
		tablur(jQuery('.rateaddbox textarea'), 'Komentarz do oceny');
		return false;
	}
	if(jQuery('.rateaddbox #ratename').val() == ''){
		alert('Proszę wpisać imię');
		return false;
	}
	if(jQuery('.rateaddbox #ratecar').val() == ''){
		alert('Proszę wpisać markę samochodu');
		return false;
	}
	return true;

}

function changerate(obj, rate){
	jQuery(obj).parent().parent().children('li').addClass('inactive').children('a').removeClass('active');
	jQuery(obj).parent().removeClass('inactive');
	jQuery('#ratevalue').val(rate);
}

function hintrating(id)
{
	jQuery('.hintrating'+id).removeClass('hidden');
}
function outhintrating(id)
{
	jQuery('.hintrating'+id).addClass('hidden');
}

function tafocus(obj, txt)
{
	if(jQuery(obj).val() == txt)
	{
		jQuery(obj).val('');
	}
	jQuery(obj).css('color', '');
}

function tablur(obj, txt)
{
	if(jQuery(obj).val() == '')
	{
		jQuery(obj).val(txt);
	}
	jQuery(obj).css('color', '#AEAEAE');
}

function toggleAirport (id_airport){

	if(jQuery('#parkings'+id_airport).hasClass('hidden')){
		jQuery('#parkings'+id_airport).removeClass('hidden');
	}else{
		jQuery('#parkings'+id_airport).addClass('hidden');
	}
}

function changeSort(id_airport, type){
	jQuery('#parkings'+id_airport+' .sort a').removeClass('ad').removeClass('au');
	if(type == 'price')
	{
		jQuery('#parkings'+id_airport+' .sort .pricelink').addClass('au');
		jQuery('#parkingsrating'+id_airport).addClass('hidden');
		jQuery('#parkingsprice'+id_airport).removeClass('hidden');
		jQuery('#orderby'+id_airport).val('price');
	}
	if(type == 'rating')
	{
		jQuery('#parkings'+id_airport+' .sort .ratinglink').addClass('ad');
		jQuery('#parkingsprice'+id_airport).addClass('hidden');
		jQuery('#parkingsrating'+id_airport).removeClass('hidden');
		jQuery('#orderby'+id_airport).val('rating');
	}
}

function changestopdays(days)
{
	jQuery('.parkingsmallcontent .stopdays').removeClass('active');
	jQuery('.parkingsmallcontent #stopdays'+days).addClass('active');

	jQuery('.parkingsmallcontent .parkingssmall').addClass('hidden');
	jQuery('.parkingsmallcontent #parkingssmall'+days).removeClass('hidden');
}

function loadRightcolumn(position, count){

	var url = "/default/index/bannerdisplay";
	var pars = 'position='+position+'&count='+count;
	jQuery.post(url, pars, function(data){
		jQuery('#adv_rightcolumn').html(data);
	});
}
function blurfocusfield(id, txt, typ)
{
	if(jQuery('#'+id).val() == '')
	{
		jQuery('#'+id).val(txt);
	}
	jQuery('#'+id).focus(function(){
		if(jQuery(this).val() == txt)
		{
			jQuery(this).val('');
		}
	});
	jQuery('#'+id).blur(function(){
		if(jQuery(this).val() == '')
		{
			if(typ != 'password')
				jQuery(this).val(txt);
		}
	});
}

function blurfield(id, txt)
{
	if(jQuery('#'+id).val() == txt)
	{
		jQuery('#'+id).val('');
	}
}

jQuery(document).ready(function() {

	if(jQuery('#remindpasswdlink').length){
		jQuery('#remindpasswdlink').click(function(){
			jQuery('#loginboxframe').slideUp(function(){
				jQuery('#remindloginboxframe').slideDown();
			});
			return false;
		});
	}
	if(jQuery('#loginlink').length){
		jQuery('#loginlink').click(function(){
			jQuery('#remindloginboxframe').slideUp(function(){
				jQuery('#loginboxframe').slideDown();
			});
			return false;
		});
	}
	if(jQuery('#changepasswdlink').length){
		jQuery('#changepasswdlink').click(function(){
			jQuery('#loggedboxframe').slideUp(function(){
				jQuery('#changepasswdboxframe').slideDown();
			});
			return false;
		});
	}
	if(jQuery('#loggedlink').length){
		jQuery('#loggedlink').click(function(){
			jQuery('#changepasswdboxframe').slideUp(function(){
				jQuery('#loggedboxframe').slideDown();
			});
			return false;
		});
	}
	if(jQuery('#loginemail').length){
		blurfocusfield('loginemail', 'e-mail parkingu', 'text');
	}
	if(jQuery('#loginpasswd').length){
		blurfocusfield('loginpasswd', 'hasło parkingu', 'password');
	}
	if(jQuery('.www').length){
		jQuery('.www').mouseover(function(){
			if(jQuery('.www').attr('rel') != '')
			{
				jQuery('.www').attr('href', jQuery('.www').attr('rel'));
			}
		});
	}
	if(jQuery('.parking').length){
	jQuery('.parking').mouseover(function() {
	 	jQuery(this).css('background','#f6f6f6');
	 	jQuery(this).children('.zobaczwiecej').removeClass('hidden');
	});
	jQuery('.parking').mouseout(function() {
	 	jQuery(this).css('background','transparent');
	 	jQuery(this).children('.zobaczwiecej').addClass('hidden');
	});
	}
	if(jQuery('.advparking').length){
	jQuery('.advparking').mouseover(function() {
	 	jQuery(this).css('background','#f6f6f6');
	});
	jQuery('.advparking').mouseout(function() {
	 	jQuery(this).css('background','transparent');
	});
	}
	if(jQuery('.parkingsmall')){
	jQuery('.parkingsmall').mouseover(function() {
	 	jQuery(this).css('background','#f6f6f6');
	 	jQuery(this).children('.parkingsmall .zobaczwiecej').removeClass('hidden');
	});
	jQuery('.parkingsmall').mouseout(function() {
	 	jQuery(this).css('background','transparent');
	 	jQuery(this).children('.parkingsmall .zobaczwiecej').addClass('hidden');
	});
	}
	if(jQuery('a.colorbox').length){
		jQuery("a.colorbox").colorbox();;
	}
	if(jQuery('a.colorboxiframe').length){
		jQuery("a.colorboxiframe").colorbox({width:"720px", height:"580px"});
	}
	if(jQuery('.paneltabs').length){
		jQuery(".paneltabs li a").mouseover(function(){
			jQuery(this).parent().parent().addClass('hover');
		});
		
		jQuery(".paneltabs li a").mouseout(function(){
			jQuery(this).parent().parent().removeClass('hover');
		});
	}

	if(jQuery('.carttabs').length){
		jQuery(".carttabs li a").mouseover(function(){
			jQuery(this).parent().parent().addClass('hover');
		});
		
		jQuery(".carttabs li a").mouseout(function(){
			jQuery(this).parent().parent().removeClass('hover');
		});
		
		jQuery(".carttabs li a").click(function(){
			jQuery(this).parent().parent().parent().children('li').removeClass('active');
			jQuery(this).parent().parent().addClass('active');
			id = jQuery(this).parent().parent().attr('id');
			jQuery('.carttabscontent').addClass('hidden');
			jQuery('#'+id+'_content').removeClass('hidden');
			return false;
		});
	}

});
