if(!Array.indexOf){
	    Array.prototype.indexOf = function(obj){
	        for(var i=0; i<this.length; i++){
	            if(this[i]==obj){
	                return i;
	            }
	        }
	        return -1;
	    }
	}

//=====================



var days;
var holidays;
var t;

if( pos == undefined )
	var pos = -50;

var note_positions = [];
	note_positions[ 1 ] = -40;
	note_positions[ 2 ] = -30;
	note_positions[ 3 ] = -20;
	note_positions[ 4 ] = -10;
	note_positions[ 5 ] = 0;

$( document ).ready( function( ){

	FLIR.init();
	FLIR.auto(['.flir']);

	var errors = $( ".error" );
	if( errors.length > 0 )
	{
		errors = $( ".error" ).prev( );
		window.scrollTo( 0, errors[0].offsetTop );
	}
		

	$( "div.stars a" ).mouseover(function(){
		var note = new String( $( this ).attr( "class" ) );
		note = note.substr( 1, 1 );

		$( this ).parent( ).removeAttr( "class" ).addClass( "stars" );
		$(this).parent( ).css( "background-position", "0px "+ note_positions[ note ] +"px" );
	});

	$( "div.stars a" ).mouseout(function(){
		$(this).parent( ).css( "background-position", "0px "+ pos +"px" );
	} );

	 $( "div.stars a" ).mouseout( );

	 $( "div.stars a" ).click( function( ){
		 var note = new String( $( this ).attr( "class" ) );
		 note = note.substr( 1 );
		 $( this ).parent( ).children( "input" ).val( note );
		 pos = note_positions[ note ];
	 } );





	$("a.fancy").fancybox({'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'overlayShow': false});

	$( ".questionList .qu a" ).click( function( ){
		var p = $( this ).next( );

		if( $.trim( p.html( ) ) == "" )
			$.get( $( this ).attr( "href" ), null, function( answer ){
					p.html( answer );
			} );


		if( p.css( "display" ) == "none" )
			$( "questionList .qu p" ).slideUp( );
		p.slideToggle( );

		return false;
	} ).next( ).hide( );

	$( "#fontplus" ).click( function( ){
		$( "#bottom a" ).css( "font-size", "13px" );
		$( "#links_map" ).css( "font-size", "13px" );
		$( ".footer" ).css( "font-size", "13px" );
		$( "#sitemap li" ).css( "font-size", "13px" );

		$( "#main_content" ).each( function( ){
			$( this ).css( "font-size", parseInt( $( this ).css( "font-size" ) ) +1 + "px"  );
		} );
		
		$( ".article span" ).css( "font-size", parseInt( $( this ).css( "font-size" ) ) +1 + "pt"  );

		return false;
	} );

	$( "#fontminus" ).click( function( ){
		$( "#bottom a" ).css( "font-size", "11px" );
		$( "#links_map" ).css( "font-size", "11px" );
		$( ".footer" ).css( "font-size", "11px" );
		$( "#sitemap li" ).css( "font-size", "11px" );

		$( "#main_content" ).each( function( ){
			$( this ).css( "font-size", parseInt( $( this ).css( "font-size" ) ) -1 + "px"  );
		} );
		
		$( ".article span" ).css( "font-size", parseInt( $( this ).css( "font-size" ) ) -1 + "pt"  );

		return false;
	} );

	$( "#printpage" ).click( function( ){

		$( "#top" ).hide( );
		$( "#bottom " ).hide( );
		$( ".links_map" ).hide( );
		$( ".footer" ).hide( );
		$( "#side" ).hide( );

		$( "body" ).css( "background", "none" );
		$( ".center" ).css( "margin", "0" );

		$( "#top" ).before( "<a href='#' id='print_normal'>wróc do normalnej wersji strony</a>" );
		$( "#print_normal" ).click( print_normal );


		window.print( );
		return false;
	} );

	function print_normal( )
	{
		$( "#top" ).show( );
		$( "#bottom" ).show( );
		$( ".links_map" ).show( );
		$( ".footer" ).show( );
		$( "#side" ).show( );

		$( "body" ).css( "background", "#FFFFFF url(res/images/drops.jpg) no-repeat scroll 50% 0" );
		$( ".center" ).css( "margin", "0 auto" );

		$( "#print_normal" ).remove( );

		return false;
	}

	$.datepicker.regional['pl'] = {
		closeText: 'Zamknij',
		prevText: '&#x3c;Poprzedni',
		nextText: 'Następny&#x3e;',
		currentText: 'Dziś',
		monthNames: ['Styczeń','Luty','Marzec','Kwiecień','Maj','Czerwiec',
		'Lipiec','Sierpień','Wrzesień','Październik','Listopad','Grudzień'],
		monthNamesShort: ['Sty','Lu','Mar','Kw','Maj','Cze',
		'Lip','Sie','Wrz','Pa','Lis','Gru'],
		dayNames: ['Niedziela','Poniedzialek','Wtorek','Środa','Czwartek','Piątek','Sobota'],
		dayNamesShort: ['Nie','Pn','Wt','Śr','Czw','Pt','So'],
		dayNamesMin: ['N','Pn','Wt','Śr','Cz','Pt','So'],
		dateFormat: 'yy-mm-dd', firstDay: 1,
		isRTL: false};
	$.datepicker.setDefaults($.datepicker.regional['pl']);
var f = false;
	$( "#datepicker" ).datepicker( {minDate: +1,
								onSelect: function( dateText, inst ){
									$( "#date" ).val( dateText );

									var opt = $( ".checklist input:checked" ).val( );
									if( opt == null )
									{
										alert( 'Przed wybraniem daty należy wybrać usługę, na którą chcesz się umówić.' );
										t = setTimeout( 'disable_days()', 1 );
									}
									else
									{
										$.get( base_href + "visit/getTime/" + dateText + "/" + opt, function( res ){
											disable_days( );
											$( "#st" ).show( );
											$( "#time_div" ).html( res )

											$( "#time_div input" ).click( function( ){
												$( "#time" ).val( $( this ).val( ) );
												$( "#time_div input" ).removeAttr( "checked" );
												$( this ).attr( "checked", "checked" );
											} );
										});
									}
								},
								onChangeMonthYear: function( y, m, ins )
								{
									if( m < 10 )
										m = "0" + m;
									$.get( base_href + "visit/days/" + y + "/" + m, function( res ){
										result = eval('(' + res + ')');

										days = result.agenda;
										holidays = result.holidays;

										disable_days( );
									});
								}} );

	$( "#offer_li input" ).click( function( ){
		var t = $( this );

		$( "#time_div" ).html( "" );

		$.get( base_href + "visit/getDesc/" + $( this ).val( ), function( result ){
			$( ".offer_desc" ).prev( ).remove( );
			$( ".offer_desc" ).remove( );

			if( result )
				t.next( ).after( "<br class=\"clear\" /><div class='offer_desc'>"+ result +"</div>" );
		} );
	} );

	$( "select#aim" ).change( function( ){
		var t = $( this );
		if( $( this ).val( ) < 1 )
			return;

		$.get( base_href + "visit/getDesc/" + $( this ).val( ), function( result ){
			$( ".aim_desc" ).prev( ).remove( );
			$( ".aim_desc" ).remove( );

			if( result )
				t.after( "<br class=\"clear\" /><div class='aim_desc'>"+ result +"</div>" );
		} );
	} );

	$(".box ul").each(function (i) {
		$(this).find("li:last").css('border', '0');
	});
	$("#items ul").find("li:last").css('background', '0');
	$("#last_act ul").find("li:last").css('border', '0').css( 'padding-left', '20px' );

	$( "#fav" ).click( function( ){
		var url = window.location.href;
		var title = document.title;

		if (window.sidebar) { // Mozilla Firefox Bookmark
			window.sidebar.addPanel(title, url,"");
		} else if( window.external ) { // IE Favorite
			window.external.AddFavorite( url, title);}
		else if(window.opera && window.print) { // Opera Hotlist
			return true;
		}
		
		return false;
	} );

	$( ".submenu_items" ).hide( );
	$( ".submenu_items[class~='open']" ).show( );

	$( ".submenu_items ul ul" ).hide( );
	$( ".submenu_items ul ul[class~='open']" ).show( );
	$( ".submenu_items ul li a" ).click( function( ){

		if( $( this ).attr( "href" ) == "#" )
		{
			$( this ).next( ).slideToggle( );

			save_open( $( this ) );

			return false;
		}
	} );

	$( ".side" ).click( function( ){
		$( this ).next( ).slideToggle( );
	} );

	$( ".submenu .submenu_items ul ul li:last-child" ).css( "border", "none" );

	var ybmi = $( "#ybmi" );
	if( ybmi.length )
	{
		window.scrollTo( 0, ybmi[ 0 ].offsetTop );
	}

	opens =  $.cookie( "open" );
	if( opens != null )
	{
		opens = opens.split( "," );

		for( var ndx = 0; ndx <= opens.length -1; ndx++ )
		{
			var open = parseInt( opens[ ndx ] );

			if( open > 0 )
				open_category( open );
		}
	}
	
	$("#gmap").googlemap({
                    controls: true,
                    labels: true,
                    zoom: 4,
                    addresses: [ "Polska, Szczecin, Królowej Korony Polskiej 24" ]
                });


	$( "#wisser #t" ).click( function( ){
		$( "#looog" ).toggle( );
		$( "#wisser" ).hide( );
		
		$( "#desc_gen" ).hide( );
		$( "#desc_tak" ).show( );

		return false;
	} );

	$( "#wisser #n" ).click( function( ){
		$( "#viiiis" ).toggle( );
		$( "#wisser" ).hide( );
		
		$( "#desc_gen" ).hide( );
		$( "#desc_nie" ).show( );

		return false;
	} );
	
	$( ".open_in_new" ).click( function( ) {

		var newWindow = window.open( $( this ).attr( 'href' ), '_blank' );
		newWindow.focus( );

		return false;
	} );

	$( "#viiiis form" ).submit( function( ){
		if( $( "#aim" ).val( ) == 8 && $.trim( $( "#notice" ).val( ) ) == "" )
		{
			alert( "W przypadku wyboru diety zdrowotnej wymagane jest wype\u0142nienie pola Uwagi." );
			return false;
		}
	});

	$( "#rand_curiosity" ).click( function( ){

		$.getJSON( base_href + "/curiosity/rand/" + $( this ).attr( "rel" ), function( json ){
			$( "#curiosities div" ).hide( "slow", function( ){ $( this ).html( json.body ).show( "slow" ) });
			$( "#rand_curiosity" ).attr( "rel", json.id );
		} );

		return false;
	} );

	$( "#change_date" ).click( function( ){
		$( "#act_d" ).hide( );
		$( "#datepicker" ).show( );

		return false;
	} );

	$( ".banner a" ).click( function( ){
		var newWindow = window.open( $( this ).attr( "href" ), "_blank" );
		newWindow.focus( );

		return false;
	} );


	aim_changed( $( "#aim" ).val( ) );
	$( "#aim" ).change( function( ){
		aim_changed( $( this ).val( ) );
	} );
} );

function aim_changed( aim )
{
	switch( aim )
	{
		// dieta odchudzająca
		case "7":
			$( "#other_header" ).html( "Dodatkowe informacje" );
			$( ".other_box" ).show( );
		break;

		// dieta zdrowotna
		case "8":
			$( "#other_header" ).html( "Nazwa choroby lub dolegliwości" );
			$( ".other_box" ).show( );
		break;

		// inny
		case "9":
			$( "#other_header" ).html( "Podaj cel wizyty" );
			$( ".other_box" ).show( );
		break;

		default:
			$( ".other_box" ).hide( );
		break;
	}
}

function open_category( cid )
{
	var a = $( ".submenu a[rel="+ cid +"]" )
	
	a.parents( "ul" ).addClass( "open" ).show( );
	a.parents( ".submenu_items" ).addClass( "open" ).show( );
	a.parent( ).find( "ul" ).addClass( "open" ).show( );

	a.parents( "ul" ).show( );
	a.parents( ".submenu_items" ).show( );
	a.parent( ).find( "ul" ).show( );
}

function disable_days( )
{
	clearTimeout( t );

	$( "#datepicker td" ).addClass( "ui-datepicker-unselectable ui-state-disabled" );
	$( "#datepicker a" ).each( function( ){
		$( this ).attr( "rel", $( this ).html( ) );
	} );

	for( day in days )
	{
		$( "#datepicker a[rel="+ day +"]" ).parent( ).removeClass( "ui-datepicker-unselectable ui-state-disabled" ).addClass( "act" );
	}

	for( holiday in holidays )
	{
		$( "#datepicker a[rel="+ holiday +"]" ).parent( ).addClass( "ui-datepicker-week-end" );
	}

	$( "#datepicker td.ui-datepicker-week-end" ).addClass( "ui-datepicker-unselectable ui-state-disabled" ).removeClass( 'act' );
}

function save_open( el )
{
	opens =  $.cookie( "open" );
	if( opens != null )
		opens = opens.split( "," );
	else
		opens = new Array( );

	id = el.attr( "rel" );

	if( ( ndx = opens.indexOf( id ) ) == -1 )
		opens.push( id );
	else
		opens[ ndx ] = undefined;

	$.cookie( "open", opens );
}

