
var browserName=navigator.appName;
var browserVer=navigator.appVersion;
var thatImage;
var operaImage;
var timer = null;
var timer2 = null;
var increment = 0;
var pathToImageDir='img/'; // set path to the image dir where are backgrounds for 'join-background-helpers'

function RegisterTreeObject() {


    $('#papirus_ent a').bind('click', function() {
        $href = $(this).attr("href");
        if ($href.search(/http/i) >= 0 || $href.search(/.jpg/i) >= 0 ||  $href.search(/.jpeg/i) >= 0
            || $href.search(/.gif/i) >= 0 || $href.search(/.png/i) >= 0 || $href.search(/.tif/i) >= 0)
        {
            return true;
        }
        LoadAjax(base_url + "/" + $(this).attr("href"));
        return false;
    });

    $("a[href$=jpeg], a[href$=gif], a[href$=jpg], a[href$=JPEG], a[href$=GIF], a[href$=JPG], a[href$=png], a[href$=PNG], a[href$=tif], a[href$=TIF]").lightBox({
        imageLoading:			page_images_url + '/lightbox/lightbox-ico-loading.gif',
        imageBtnPrev:			page_images_url + '/lightbox/lightbox-btn-prev.gif',
        imageBtnNext:			page_images_url + '/lightbox/lightbox-btn-next.gif',
        imageBtnClose:			page_images_url + '/lightbox/lightbox-btn-close.gif',
        imageBlank:			page_images_url + '/lightbox/lightbox-blank.gif'
    });
}
function LoadAjax(url) {
    $("#papirus_ent").html("Ładuję stronę...");
    $.ajax({
        type: "POST",
        url: url,
        data: "ajax=true",
        success: function(msg){
            msg = msg + '<br class="cb"/>';
            $("#papirus_ent").html(msg);

            $.ifixpng(page_images_url + '/ifixpng.gif');
            $("*").each(function() {
                $(this).ifixpng();
            });
            RegisterTreeObject();
        }
    });
}


function GetFlashMovie(movieName) {
    var isIE = navigator.appName.indexOf("Microsoft") != -1;
    return (isIE) ? window[movieName] : document[movieName];
}
function PlayMusic(name) {
    var flash = GetFlashMovie("top_flash");
    if (flash) {
        flash.PlayFlashMusic(name);
        return true;
    }
    return false;
}
function StopFlashMusic() {
    GetFlashMovie("top_flash").StopFlashMusic();
}

function getTextFromFlash(str) {
    document.htmlForm.receivedField.value = "From Flash: " + str;
    return str + " received";
}
function Navigate(action) {

    var isIE = navigator.appName.indexOf("Microsoft") != -1;
    if (action == 'kontakt' || isIE) {
        document.location.href = base_url + "/" + action;
        return;
    }
    if (action == 'media') {
        StopFlashMusic();
    } else {
        if (action == 'impresariat' || action == 'instrumenty')
            PlayMusic('index');
        else
            PlayMusic(action);
    }
    LoadAjax(base_url + "/" + action);
    

}

$(document).ready( function() {
    RegisterTreeObject();
    //adding the corners with these parameters to everyone div with 'corner' class
    //$('.corner').corner("round 8px").parent().css('padding', '2px').corner("round 10px");
    //$('.corner').parent().css('background-color', '#E1E3E2');
    //to use that - paste file inclusion of jquery.corner.js in HEAD section:
    //<script type="text/javascript" src="js/jquery.corner.js"></script>
	
    if (browserName == "Microsoft Internet Explorer" && browserVer.indexOf(6.0) > -1) {
    // this one should runs on ie6
    }
	
    if (browserName == "Microsoft Internet Explorer" && browserVer.indexOf(7.0) > -1) {
        // this one should runs on ie6
        $('head').append('<link rel="stylesheet" href="./css/ie7.css" media="screen" type="text/css" />');
    }
	
    $("ul.downiconsul li a").hover(function() {
        $(this).find('span').css("visibility","hidden");
        $(this).find('img').show().stop()
        .animate({
            width: '363px',
            height: '42px',
            marginTop: '-50px'
        }, 1000);

    } , function() {
        $(this).find('img')
        .animate({
            height: '0px',
            width: '0px',
            marginTop: '0px'
        }, 10);
        $(this).find('img').hide().stop()
        $(this).find('span').css("visibility","visible");
    });


    $('#flash1').flash({
        src: 'application/public/flash/top_flash.swf',
        width: 1003,
        wmode: 'transparent',
        height: 256,
        id: 'top_flash',
        name: 'top_flash'
    });

    $('.menu').flash({
        src: 'application/public/flash/wachlarz' + page_language + '.swf',
        wmode: 'transparent',
        width: 252,
        height: 357
    });
    $('#head').css("background-image",'url("'+ base_url + '/application/public/img/head' + page_language +'.gif")');

    $('#polandClock').click( function() {
        document.location = base_url + "/index/index/language/0";
    });
    $('#britainClock').click( function() {
        document.location = base_url + "/index/index/language/1";
    });
    $('#japanClock').click( function() {
        document.location = base_url + "/index/index/language/2";
    });

    britainClock();
    poland();
    japanClock();


});
//sztuka bo przy pierwszym wywołaniu PlayMusic('kontakt') obiekt flasha nie istnieje
function TryPlayKontakt() {
   if (PlayMusic('kontakt')) {
       clearTimeout(timer2);
   }
}
if (document.location.href.search("kontakt") > 0) {
    timer2 = setTimeout("TryPlayKontakt()",1000);
}

function calcTime (interval)
{
    var currentTime = new Date ();

    var currentHours = currentTime.getHours ( );
    var currentMinutes = currentTime.getMinutes ( );
    var currentSeconds = currentTime.getSeconds ( );

    // Pad the minutes and seconds with leading zeros, if required
    currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
    currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;

    currentHours += interval;
    if (currentHours < 0)
        currentHours += 24;

    currentHours = ( currentHours > 24 ) ? currentHours - 24 : currentHours;

    var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM";

    // Convert the hours component to 12-hour format if needed
    currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours;

    // Convert an hours component of "0" to "12"
   // currentHours = ( currentHours == 0 ) ? 12 : currentHours;

    // Compose the string for display

    //currentHours-=1;

    var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds + " " + timeOfDay;

    return currentTimeString;
}

function britainClock ( )
{
    var currentTimeString = calcTime(-1);
  
    $('#britainClock').html(currentTimeString);
    timer = setTimeout("britainClock()",1000)
}

function japanClock ( )
{
    var currentTimeString = calcTime(7);
  
    $('#japanClock').html(currentTimeString);
    timer = setTimeout("japanClock()",1000)
}


function poland(){
    var time = new Date()
    var hours = time.getHours()
    var minutes = time.getMinutes()
    minutes=((minutes < 10) ? "0" : "") + minutes
    var seconds = time.getSeconds()
    seconds=((seconds < 10) ? "0" : "") + seconds
    var clock = hours + ":" + minutes + ":" + seconds
    $('#polandClock').html(clock);
    timer = setTimeout("poland()",1000)
}
