var timeout = 500;
var closetimer		= 0;
var ddmenuitem      = 0;

function nav_open()
{	nav_canceltimer();
	nav_close();
	ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');}

function nav_close()
{	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function nav_timer()
{	closetimer = window.setTimeout(nav_close, timeout);}

function nav_canceltimer()
{	if(closetimer)
	{	window.clearTimeout(closetimer);
		closetimer = null;}}
		
$(document).ready(function(){

/*
* Based on: http://javascript-array.com/scripts/jquery_simple_drop_down_menu/
*/
$('#nav > li').bind('mouseover', nav_open);
$('#nav > li').bind('mouseout',  nav_timer);

$(document).click(nav_close);

if(typeof(doMieszkania) == "function"){
    doMieszkania();
}

/*
// create placehgolder for plans

osiedle = $("#osiedle").css({
        'width':    '600px',
        'height':   '300px',
        'background-color': 'navy',
        'border':   '1px solid silver',
        'margin-bottom':    '20px'
});

plan = $("#plan").css({
        'display':  'none',
        'width':    '600px',
        'height':   '300px',
        'background-color': 'pink',
        'border':   '1px solid silver',
        'margin-bottom':    '20px'
});
back2osiedle = $("#back2osiedle");

plan.find('li').css('display', 'none');

osiedle.find("area#mpietro1").click(function(){
   $("#osiedle").fadeOut(250,function(){
    $("#plan").fadeIn(250);
    }); 
});

back2osiedle.click(function(e){
   $("#plan").fadeOut(250,function(){
    $("#osiedle").fadeIn(250);
    $(this).fadeOut(250);
    });
   e.preventDefault();
});

osiedle.hover(function(){
    row = $("#mieszkanie tbody tr:eq(0), #mieszkanie tbody tr:eq(1)");
    row.css({"border":"1px red dotted"});
},function(){
    $("#mieszkanie tbody tr:eq(0), #mieszkanie tbody tr:eq(1)").css({'border': '1px none black'});
});

// table#mieszkania interaction
$("#mieszkanie tbody tr:odd").addClass("even")
$("#mieszkanie tbody tr").hover(function(){
    $(this).addClass("hover");
},function(){
    $(this).removeClass("hover");
});

$("#mieszkanie tbody tr").click(function(e){

    //txt = $(this).parent().find("tr").index(this)+1 + ": " + $(this).find("td:first").text();
    planNum = $(this).parent().find("tr").index(this)+1;
    
    var plan = $("#plan");
    $.scrollTo(plan, 100, 'easeOutExpo');
    //hide #osiedle, then #plan and change text and show #plan
    $("#osiedle").fadeOut(250,function(){
        plan.fadeOut(250, function(){
            plan.find('li').css('display', 'none');
            plan.find('li#plan' + planNum).css('display', 'block');
            plan.fadeIn(500);
        });        
    });
});
*/

/*################################################*/
// enable slideshow on modern browsers, skip ie6
if(jQuery.browser['msie'] && jQuery.browser.version == "6.0"){
    // upgrade to newer IE or Firefox :)
}else{
/* find all .slideshow elements, gets it's predeclared number of pictures (predeclared in body of each slideshow)
  in "name_slideshow variables eg.:
  <ul id="one" class="slideshow">
  <scrip> one_slideshow = 7;</script>
  ...
  </ul>
  
  and generate that much <li> in each slideshow
*/
/*
ids = new Object;
var ids;
$(".slideshow").each(function(i){
id = $(this).attr('id');
ids[id] = eval(id + "_slideshow");
});

for(id in ids){
    numOfPics = ids[id];
    slideshow = $("#"+ id +".slideshow li").html();
    $("#"+ id +".slideshow").html("");
    for(i = 1; i <= numOfPics; i++){
        // replace # (or anything else) with bigpic#.jpg in a
        // generate <li>'s with consecutive filenames
        // path=$3 fname=$4 base=$5 ext=$6
        el = "<li>" + slideshow.replace(/(^.+?")(?:.+)(".+?<img.+src=\"(.+\/))((.+?)[0-9]+(\..+?))\"(.+)/, "$1$3big$5"+ i +"$6$2$5" + i + "$6\"$7") + "</li>";
        $("#"+ id +".slideshow").append(el);
    }
    $("#"+ id +".slideshow").innerfade({
        animationtype: 'fade',
        speed: 'slow',
        timeout: '5000',
        type: 'random_start',
        containerheight: '300px',
        runningclass: 'innerfade'
    });
} // for
delete ids;
*/
} // if

$(".slideshow, #wnetrza").innerfade({
	animationtype: 'fade',
	speed: 'slow',
	timeout: '5000',
	type: 'sequence',
	containerheight: '300px',
	runningclass: 'innerfade'
});

$(".slideshow a").fancybox();
$("#wnetrza a, #lokal").fancybox();

});

