function print(url) {
    window.open(url, 'invest', 'toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=no,fullscreen=no,channelmode=no,width=820,height=610, left=0, top=0');
    return false;
}

function setMainPageBg() {
    var windowWidth = $(window).width();
    var windowHeight = $(window).height();
    var backgroundPath = "/mainpageimg/miniatura.php?name=main.jpg&rx=" + windowWidth;

    $("body").css("background", "url(" + backgroundPath + ") top center no-repeat");

    $("div#mainPageNavi").css("margin-top", ((windowHeight/2)-88) + "px" );
}

function setPageBg() {
    var windowHeight = $(window).height();
    var documentHeight = $(document).height();

    if( documentHeight <= windowHeight ) {
        $("div#subMenu").css("height", (windowHeight-96) + "px" );
    } else {
        $("div#subMenu").css("height", (documentHeight-96) + "px" );
    }
}

function lightOfferMenu( itemID ) {
    $("li#desc").attr("class", "").attr("style","font-weight:normal");
    $("li#geomap").attr("class", "").attr("style","font-weight:normal");
    $("li#photo").attr("class", "").attr("style","font-weight:normal");
    $("li#gm").attr("class", "").attr("style","font-weight:normal");
    $("li#download").attr("class", "").attr("style","font-weight:normal");
    $("li#localization").attr("class", "").attr("style","font-weight:normal");
    $("li#mpzp").attr("class", "").attr("style","font-weight:normal");

    $("li#" + itemID).attr("class", "active").attr("style","font-weight:bold");
}

function showOffer( itemID, lang, offerID ) {
    $("div.fullDesc").hide();
    $("div#map_canvas").hide();
    $("div#offerContent").slideUp(750, function() {
        $("div#map_canvas").hide();
        $.get("/ajax/" + itemID + "/lang_" + lang + "/immo_" + offerID + ".end", function(strHTML) {
                    $("div#map_canvas").hide();
                    $("div#offerContent").html(strHTML).slideDown(750, function() {
                        if( itemID == "desc" ) {
                            $("div.fullDesc").fadeIn( 250 );
                        }
                        if( itemID == "gm" ) {
                            $("div#map_canvas").show();
                            $(document).ready( initialize() );
                        }

                        if( itemID != "gm" ) {
                            $("div#map_canvas").hide();
                        }
                    });

                    $("p.print").html( '<img src="/images/agt_print.png" alt="drukuj" title="drukuj" onclick="print(\'/druk/' + itemID + '/' + offerID + '.html?lang=' + lang + '\');"/>' );
                 });
        lightOfferMenu( itemID );
    });

}

function extendOffer( itemID, lang, offerID, highligt ) {
    $("div#offerContent").slideUp(750, function() {
        $.get("/ajax/" + itemID + "/lang_" + lang + "/immo_" + offerID + ".end", function(strHTML) {
                    $("div#offerContent").html(strHTML).slideDown(750);
                    $("p.print").html( '<img src="/images/agt_print.png" alt="drukuj" title="drukuj" onclick="print(\'/druk/' + itemID + '/' + offerID + '.html?lang=' + lang + '\');"/>' );
                 });
        lightOfferMenu( highligt );
    });
}

function shownew( element, imgWidth, imgHeight, itemNumber, totalItems, photoID, lang )
{
	var file = element.src;
    var calcSH = 500;
	var plainFile;
    if( file.indexOf("190_") !== -1 ) {
        plainFile = file.replace( '190_', 'orig_' );
    } else {
        plainFile = file.replace( '100_', 'orig_' );
    }
	file = plainFile;

    var windowWidth = $(window).width();
    var windowHeight = $(window).height()-100;

    var scale = ( windowHeight - 40 ) / imgHeight;
    var newWidth = Math.ceil( imgWidth * scale );
    var newHeight = windowHeight;

    var marginLeft = Math.ceil( ( windowWidth - newWidth ) / 2 );

    var prevItem = itemNumber - 1;
    var nextItem = itemNumber + 1;

    if( prevItem < 0 ) {
        prevItem = totalItems - 1;
    }

    if( nextItem == totalItems ) {
        nextItem = 0;
    }

    var arrowMargin = Math.ceil( ( windowWidth - newWidth ) / 2 ) - 25;

	var photoContainer = document.getElementById( "bigphoto" );
	photoContainer.innerHTML = '<p style="color:#ffffff;cursor:pointer;margin-top:20px;text-align:right;width:' + newWidth + 'px;margin:0 auto;" onclick="closePhoto()">[x]</p>' +
            '<a href="javascript:showItem(' + prevItem + ');" style="float:left;margin-left:' + arrowMargin + 'px;margin-top:' + (Math.ceil(newHeight/2)) +'px"><img src="/images/photoArrowLeft.png" alt="" /></a><span style="width:' + (newWidth-50) + 'px"></span>' +
            '<a href="javascript:showItem(' + nextItem + ');" style="float:right;margin-right:' + arrowMargin + 'px;margin-top:' + (Math.ceil(newHeight/2)) +'px"><img src="/images/photoArrowRight.png" alt="" /></a>' +
            '<div style="width:' + newWidth + 'px; height:' + newHeight + 'px;margin-left:' + marginLeft + 'px">' +
            '<img src="' + file + '" style="width:' + imgWidth + 'px; height:' + imgHeight + 'px" id="bigImage" />' +
            '<p class="print" style="text-align:right;"><img src="/images/agt_print2.png" alt="drukuj" title="drukuj" style="cursor:pointer" onclick="print(\'/druk/sphoto/photo.html?photo=' + photoID + '&lang=' + lang + '\');"/></p>' +
            '</div>';

    $("#bigphoto").attr( "style", "display:block" );

	jQuery(function($){
		$('#bigImage').smoothZoom({
			width: newWidth,
			height: newHeight,
			button_SIZE: 22,
			button_ALIGN: "bottom center",
			zoom_OUT_TO_FIT: "NO",
			button_AUTO_HIDE: "YES",
			button_AUTO_HIDE_DELAY: 2
		});
	});

}

function showItem( itemNumber )
{
    var totalItems = photoFiles.length;
    var item = photoFiles[itemNumber];

    var itemArray = item.split('|');

	var file = itemArray[0];
    var imgWidth = itemArray[1];
    var imgHeight = itemArray[2];
    var photoID = itemArray[3];
    var lang = itemArray[4];
    var calcSH = 500;
	var plainFile;
    if( file.indexOf("190_") !== -1 ) {
        plainFile = file.replace( '190_', 'orig_' );
    } else {
        plainFile = file.replace( '100_', 'orig_' );
    }
	file = plainFile;

    var windowWidth = $(window).width();
    var windowHeight = $(window).height()-100;

    var scale = ( windowHeight - 40 ) / imgHeight;
    var newWidth = Math.ceil( imgWidth * scale );
    var newHeight = windowHeight;

    var marginLeft = Math.ceil( ( windowWidth - newWidth ) / 2 );

    var prevItem = itemNumber - 1;
    var nextItem = itemNumber + 1;

    if( prevItem < 0 ) {
        prevItem = totalItems - 1;
    }

    if( nextItem == totalItems ) {
        nextItem = 0;
    }

    var arrowMargin = Math.ceil( ( windowWidth - newWidth ) / 2 ) - 25;

	var photoContainer = document.getElementById( "bigphoto" );
	photoContainer.innerHTML = '<p style="color:#ffffff;cursor:pointer;margin-top:20px;text-align:right;width:' + newWidth + 'px;margin:0 auto;" onclick="closePhoto()">[x]</p>' +
            '<a href="javascript:showItem(' + prevItem + ');" style="float:left;margin-left:' + arrowMargin + 'px;margin-top:' + (Math.ceil(newHeight/2)) +'px"><img src="/images/photoArrowLeft.png" alt="" /></a><span style="width:' + (newWidth-50) + 'px"></span>' +
            '<a href="javascript:showItem(' + nextItem + ');" style="float:right;margin-right:' + arrowMargin + 'px;margin-top:' + (Math.ceil(newHeight/2)) +'px"><img src="/images/photoArrowRight.png" alt="" /></a>' +
            '<div style="width:' + newWidth + 'px; height:' + newHeight + 'px;margin-left:' + marginLeft + 'px">' +
            '<img src="' + file + '" style="width:' + imgWidth + 'px; height:' + imgHeight + 'px" id="bigImage" />' +
            '<p class="print" style="text-align:right;"><img src="/images/agt_print2.png" alt="drukuj" title="drukuj" style="cursor:pointer" onclick="print(\'/druk/sphoto/photo.html?photo=' + photoID + '&lang=' + lang + '\');"/></p>' +
            '</div>';

    $("#bigphoto").attr( "style", "display:block" );

	jQuery(function($){
		$('#bigImage').smoothZoom({
			width: newWidth,
			height: newHeight,
			button_SIZE: 22,
			button_ALIGN: "bottom center",
			zoom_OUT_TO_FIT: "NO",
			button_AUTO_HIDE: "YES",
			button_AUTO_HIDE_DELAY: 2
		});
	});
}

function show( element, imgWidth, imgHeight )
{
	var file = element.src;
    var calcSH = 500;
	var plainFile;
    if( file.indexOf("190_") !== -1 ) {
        plainFile = file.replace( '190_', calcSH + '_' );
    } else {
        plainFile = file.replace( '100_', calcSH + '_' );
    }
	file = plainFile; '500' + plainFile.substring( 3, plainFile.length );
	
	var photoContainer = document.getElementById( "bigphoto" );
	photoContainer.innerHTML = '<div id="zoom01"><img id="thePhoto" class="hand" onclick="closePhoto()" src="' + file + '" ' +
            'alt="Kliknij aby zamknąć" title="Kliknij aby zamknąć" /></div>';

    var calcSW = Math.ceil( ( calcSH * imgWidth ) / imgHeight );
    $("#zoom01").gzoom({
						sW: calcSW,
						sH: calcSH,
						lW: imgWidth,
						lH: imgHeight,
						lighbox : true
				        });
    var windowWidth = $(window).width();
    var windowHeight = $(window).height();

    var marginTop = ( windowHeight - calcSH ) / 2;
    var marginLeft = ( windowWidth - calcSW ) / 2;

    $("div.gzoomwrap").attr( "style", "margin-top:" + marginTop + "px;margin-left:" + marginLeft + "px;" );
    $("#bigphoto").attr( "style", "display:block" );
}

function showWithPath( path, imgWidth, imgHeight )
{
    var file =path;
    var calcSH = 500;
    var plainFile;
    if( file.indexOf("190_") !== -1 ) {
        plainFile = file.replace( '190_', 'orig_' );
    } else {
        plainFile = file.replace( '100_', 'orig_' );
    }
    file = plainFile;

    var windowWidth = $(window).width();
    var windowHeight = $(window).height()-100;

    var scale = ( windowHeight - 40 ) / imgHeight;
    var newWidth = Math.ceil( imgWidth * scale );
    var newHeight = windowHeight;

    var marginLeft = Math.ceil( ( windowWidth - newWidth ) / 2 );

    var photoContainer = document.getElementById( "bigphoto" );
    photoContainer.innerHTML = '<p style="color:#ffffff;cursor:pointer;margin-top:20px;text-align:right;width:' + newWidth + 'px;margin:0 auto;" onclick="closePhoto()">[x]</p>' +
            '<div style="width:' + newWidth + 'px; height:' + newHeight + 'px;margin-left:' + marginLeft + 'px">' +
            '<img src="' + file + '" style="width:' + imgWidth + 'px; height:' + imgHeight + 'px" id="bigImage" />' +
            '</div>';

    $("#bigphoto").attr( "style", "display:block" );

    jQuery(function($){
        $('#bigImage').smoothZoom({
            width: newWidth,
            height: newHeight,
            button_SIZE: 22,
            button_ALIGN: "bottom center",
            zoom_OUT_TO_FIT: "NO",
            button_AUTO_HIDE: "YES",
            button_AUTO_HIDE_DELAY: 2
        });
    });

}

function closePhoto()
{
	var photoContainer = document.getElementById( "bigphoto" );
	photoContainer.innerHTML = '';
	photoContainer.style.display="none";
}

function nl( b )
{
	document.getElementById("nl_action").value = b;
	document.getElementById("nl_form").submit();
}

function showMsg( msg )
{
	alert( msg );
}

var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open()
{  jsddm_canceltimer();
   jsddm_close();
   ddmenuitem = $(this).find('ul').css('visibility', 'visible');}

function jsddm_close()
{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function jsddm_timer()
{  closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{  if(closetimer)
   {  window.clearTimeout(closetimer);
      closetimer = null;}}

$(document).ready(function()
{  $('#jsddm > li').bind('mouseover', jsddm_open)
   $('#jsddm > li').bind('mouseout',  jsddm_timer)});

document.onclick = jsddm_close;
