// fce vlozi do containeru pro obrazek galerie zadany obrazek
function showGalleryImage(iPhoto) {
    if (typeof galleryPhotosData != 'undefined' && galleryPhotosData.length > 0) {
        var title = galleryPhotosData[iPhoto]['description'];
        var position = galleryPhotosData[iPhoto]['position'];
        var href = galleryPhotosData[iPhoto]['link'];
        var previousLink = '';
        var nextLink = '';
        
        jQ("#galleryFullImageContainer").empty();
        if (typeof galleryPhotosData[iPhoto-1] != 'undefined') {
            previousLink = '<div class="gallery_previous" onclick="showGalleryImage(' + (iPhoto-1) + ');"></div>';
        }
        if (typeof galleryPhotosData[iPhoto+1] != 'undefined') {
            nextLink = '<div class="gallery_next" onclick="showGalleryImage(' + (iPhoto+1) + ');"></div>';
        }
         
        var content = '<table><tr><td class="previous">' + previousLink + '</td><td><div class="original_photo_size"><p><strong>' + title + '</strong><br />'+ 'Photo' +' ' + position + '</p><img src="' + href + '" alt="' + title + '" title="' + title + '" /></div></td><td class="next">' + nextLink + '</td></tr></table>';
        
        jQ("#galleryFullImageContainer").append(content);
    }
}




// nacteni nabidek pres ajax a zapis do daneho containeru
function getHotelDetail(sHotelId, bDetail) {
    
    // promenne jsHost, extQueryStr, urlHalves, sUrlPathDetail musi byt nadefinovane v skriptu stranky!!!    
    var sUrlPathDetail = jsHost + window.location.hostname + '/' + extQueryStr + '/ajaxHotelRoomDetail.php';
  	var sReplyData = null;
  	var sDivDetailContainer = "#lbIframe";
  	var sQuery = urlHalves[1];
  	var error = null;
  	
  	if (bDetail) {
  	    sQuery = sQuery + '&roomId='+sHotelId;
  	} else {
  	     sQuery = sQuery + '&hotelId='+sHotelId;
  	}
  	
	showLoadingBox(true);
	
  	jQ.ajax({
    	type: "GET",
    	url: sUrlPathDetail,
    	data: sQuery,
    	dataType: "xml",
    
    	success: function(replyData) {
    	    
    	    // Pokud je na ajaxove strance chyba
			error = jQ(replyData).find('/root/error');
			errorMessage = jQ(error).text();
			
			// pokud vyprsela session a mam provest redirect
			if (errorMessage.length > 0 && errorMessage == 'SESSION_EXPIRED_MAKE_INDEX_REDIRECT') {
			    var jsHost = (("https:" == document.location.protocol) ? "https://" : "http://");
			    var redirectUrl = jsHost + window.location.hostname + '/?error=expired';
			    stopLoading();
			    showLoadingBox(false);
			    window.location.href = redirectUrl;
			    return false;
			}

			// ostatni chyby zobrazim na standardnim miste
			if(errorMessage.length > 0) { 
				stopLoading();
				showLoadingBox(false);
				jQ('#lbOverlay').hide();
				prepareErrorCloseMsgTo(errorMessage, '#box');
				return false;
			}
    	    
         	// vraceni obsahu description
     		sReplyData = jQ(replyData).find('/root/page/description').text();
         	
         	if (sReplyData != "") {
         		jQ(sDivDetailContainer).empty().append(sReplyData);
         	}

			showLoadingBox(false);
		} ,
	   
	   	error: function(xmlObject, errorMsg, exception) {
			 //window.status += errorMsg;
			errorMessage = '<div class="mspc_detail_wrapper"><div class="error">' + 'Communication error with reservation system' + '</div></div>';
			prepareErrorMsgTo(errorMessage, sDivDetailContainer);
			showLoadingBox(false);
	   	} 
	});

}

// fce prijde vsechny obrazky ze zacinajim id a overi zda se korektne nahrali, jinak vlozi default img
function checkAllRemoteHotelImages() {
    jQ("img[@id ^= 'remoteHotelImg_']").each(function () {
        if (!this.complete || (typeof this.naturalWidth != 'undefined' && this.naturalWidth == 0)) {
            jQ(this).attr("src", "images/htl/ico_no_foto.gif");
        }
        
    });
}


// FOR DELETE
/*
// wait for page to load
$(document).ready(function() {
    // add fixBroken code to all images on the document
    $('img').fixBroken();
});

jQ.fn.fixBroken = function(){
    return this.each(function(){
        var tag = jQ(this);
        var alt_img = 'offline.jpg';
        tag.error(function() { // this adds the onerror event to images
            tag.attr("src",alt_img); // change the src attribute of the image
            return true;
        } );
    });
};

$(window).load(function() {
    $(’img’).each(function() {
        if (!this.complete || typeof this.naturalWidth == “undefined” || this.naturalWidth == 0) {
        // image was broken, replace with your new image
        this.src = ‘http://www.tranism.com/weblog/images/broken_ipod.gif’;
        }
    });
});
*/
