﻿function fj_findObj(n, d) {
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = fj_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function fj_showHideLayers() {
    var i, p, v, obj, args = fj_showHideLayers.arguments;
    for (i = 0; i < (args.length - 2); i += 3) if ((obj = fj_findObj(args[i])) != null) {
        v = args[i + 2];
        if (obj.style) { obj = obj.style; v = (v == 'show') ? 'visible' : (v == 'hide') ? 'hidden' : v; }
        obj.visibility = v;
    }
}

function contentLoaded() {

    $('#s_text_cont').data('jsp').reinitialise();
    $("a[rel=stavba]").fancybox({
        'titlePosition': 'over',
        'titleFormat': function (title, currentArray, currentIndex, currentOpts) {
            return '<span id="fancybox-title-over">' + (currentIndex + 1) + ' / ' + currentArray.length + '</span>';
        }
    });


}


$(document).ready(function () {


    $("a[rel=gallery]").fancybox({
        'titlePosition': 'over',
        'titleFormat': function (title, currentArray, currentIndex, currentOpts) {
            return '<span id="fancybox-title-over">' + (currentIndex + 1) + ' / ' + currentArray.length + '</span>';
        }
    });

    $("a[rel=stavba]").fancybox({
        'titlePosition': 'over',
        'titleFormat': function (title, currentArray, currentIndex, currentOpts) {
            return '<span id="fancybox-title-over">' + (currentIndex + 1) + ' / ' + currentArray.length + '</span>';
        }
    });

    $("a[rel=servis]").fancybox({
        'titlePosition': 'over',
        'titleFormat': function (title, currentArray, currentIndex, currentOpts) {
            return '<span id="fancybox-title-over">' + (currentIndex + 1) + ' / ' + currentArray.length + '</span>';
        }
    });



    // http: //maps.google.com/maps/ms?msid=213396176141316872163.0004a744a235baf43f5b5&msa=0

    
    $(".iframe_map").fancybox({
        'type': 'iframe',
        'width': '75%',
        'height': '75%'
    });


    //    $(".def_map_btn").fancybox({
    //        'titleFormat': function (title, currentArray, currentIndex, currentOpts) {
    //            return '<span id="fancybox-title-wrap"><span id="fancybox-title-left"/><span id="fancybox-title-main">' + title + ' - <a href="http://maps.google.com/maps/ms?msid=213396176141316872163.0004a744a235baf43f5b5&msa=0" target="_blank">Google Maps</a></span><span id="fancybox-title-right"/></span>';
    //        }
    //    });

//    $(".kontakty_map_btn").fancybox({
//        'titleFormat': function (title, currentArray, currentIndex, currentOpts) {
//            return '<span id="fancybox-title-wrap"><span id="fancybox-title-left"/><span id="fancybox-title-main">' + title + ' - <a href="http://maps.google.com/maps/ms?msid=213396176141316872163.0004a744a235baf43f5b5&msa=0" target="_blank">Google Maps</a></span><span id="fancybox-title-right"/></span>';
//        }
//    });

    $(".def_new_img").fancybox({
        'titleShow': false
    });

    PEPS.rollover.init();

    //    $(".tt").tooltip({
    //        tip: "#tooltip",
    //        position: "top center"
    //    });

    $(".lang_eng").tooltip({
        tip: ".tt_eng",
        effect: "fade",
        position: "bottom left",
        offset: [10, 10]
    });

    $(".lang_ger").tooltip({
        tip: ".tt_ger",
        effect: "fade",
        position: "bottom left",
        offset: [10, 10]
    });

    $(".tb_price").focus(function () {
        $(".tb_price").val("");
    });


    //scrollpane init
    $('#def_txt').jScrollPane();
    $('#s_text_cont').jScrollPane();
    $('#s_text').jScrollPane({ animateTo: true, animateInterval: 50, animateStep: 5 });

    $('a.scroll_to').bind(
					'click',
					function () {
					    $this = $(this);
					    var destinationSelector = $(this).attr('rel');
					    $('#s_text', $this.parent().parent().parent()).each(
							function () {
							    this.scrollTo(destinationSelector);
							}
						);
					    return false;
					}
				);

    //slide show functionality

    $('.kontakt_name').watermark('Jméno');
    $('.kontakt_email').watermark('Emailová adresa');
    $('.kontakt_body').watermark('Text zprávy');

    //    $("a#btnPozvanka").fancybox(
    //    {
    //    overlayOpacity: 0.75,
    //    overlayColor: '#000'
    //    });
    //    $("a#btnPozvanka").trigger('click');

});


function load_image(image) {
    // $('#example-placeholder').html('<p><img src="/images/ajax-loader.gif" width="220" height="19" /></p>');
    // $('#s_img_cont').html('xxxx dasdasdsa asd asd ');
    $('#s_img_cont').html('<img src="' + image + '"/>');
}


PEPS = {};



PEPS.rollover =
        {
            init: function () {
                this.preload();

                $(".ro").hover(
         function () { $(this).attr('src', PEPS.rollover.newimage($(this).attr('src'))); },
         function () { $(this).attr('src', PEPS.rollover.oldimage($(this).attr('src'))); }
      );
            },

            preload: function () {
                $(window).bind('load', function () {
                    $('.ro').each(function (key, elm) { $('<img>').attr('src', PEPS.rollover.newimage($(this).attr('src'))); });
                });
            },

            newimage: function (src) {
                return src.substring(0, src.search(/(\.[a-z]+)$/)) + '_ro' + src.match(/(\.[a-z]+)$/)[0];
            },

            oldimage: function (src) {
                return src.replace(/_ro\./, '.');
            }
        };

/** slideshow functionality **/

$(document).ready(function () {

    var intervalID = setInterval("showNextImage()", 10000);

    $(".ss_thumb").click(function () {

        if (!$(this).hasClass("ss_thumb_sel")) {
            var imgId = $(this).find("img").attr("alt");
            $(".ss_image:visible").hide();
            $(".ss_image img[alt=" + imgId + "]").parent().parent().fadeIn(1000);

            clearInterval(intervalID);
            intervalID = setInterval("showNextImage()", 10000);
            $(".ss_thumb_sel").removeClass("ss_thumb_sel");
            $(this).addClass("ss_thumb_sel");
        }
    });


});

function showNextImage() {

    var currentImage = $(".ss_image:visible");
    var currentThumb = $(".ss_thumb_sel");

    if ($(currentThumb).next().length > 0) {
        $(currentThumb).next().addClass("ss_thumb_sel");
    }
    else {
        $(".ss_thumb:first").addClass("ss_thumb_sel");
    }

    $(currentThumb).removeClass("ss_thumb_sel");

    if ($(currentImage).next().length > 0) {
        $(currentImage).next().fadeIn(1000);
    }
    else {
        $(".ss_image:first").fadeIn(1000);
    }

    $(currentImage).hide();
}

