﻿/// <reference path="jquery-1.3.2.js" />
var menuQuantity = 40; //liczba wszystkich .menu-item a
//start aplikacji strona główna
$(document).ready(function() {
    //$('#content').hide().load('subpages/strona_glowna.html', function() {
    //    $(this).fadeIn();
    //});
    //$('.menu-item a').removeClass();
    //$('.menu-item a').addClass('menu-item');
    //$('.menu-item a').eq(0).addClass('selected');
    $('#hidebotimg').attr({
        'src': 'resource/bullet_toggle_minus.png',
        'alt': '+'
    });
    return false;

});

/******************************************************/
//obsługa menu primary-nav
$(document).ready(function() {
    // Initialize history plugin.
    // The callback is called at once by present location.hash.
    $.historyInit(pageload);

    $(".menu-item a[rel='history']").live('click', function() {
        var ahref = $(this).attr("href");
        ahref = ahref.replace(/^.*#/, '');
        // moves to a new page. 
        // pageload is called at once.
        $.historyLoad(ahref);
        $('.menu-item a').removeClass().addClass('menu-item');
        $(this).addClass('selected');
        return false;
    });

    $("#showDemo").live('click', function() {
        var site;
        if ($("#demo3").is(':checked')) {
            site = "demo.php?demo=3&site=" + $("#adres").val();
        }
        else if ($("#demo2").is(':checked')) {
            site = "demo.php?demo=2&site=" + $("#adres").val();
        }
        else {
            site = "demo.php?demo=1&site=" + $("#adres").val();
        }

        window.open(site);
        return false;
    });

});

// This function is called when:
// 1. after calling $.historyInit();
// 2. after calling $.historyLoad();
// 3. after pushing "Go Back" button of a browser
function pageload(ahref) {
    $('.menu-item a').removeClass().addClass('menu-item');

    // ahref doesn't contain the first # character.
    if (ahref) {
        // restore ajax loaded state
        $("#content").load(ahref);
    } else {
        // start page
        $("#content").load('subpages/strona_glowna.html');
        $('.menu-item a').removeClass().addClass('menu-item');
        $('.menu-item a').eq(0).addClass('selected');
    }
    //wyszukuje odpowiednie menu-item do zaznaczenia podczas naciskania przycisku powrót w przeglądarce
    for (i = 1; i < menuQuantity; i++) {
        //alert($(' .menu-item a').size());
        if ($('.menu-item a').eq(i).attr("href") == ahref) {
            //alert(ahref + " dla i = " + i);
            $('.menu-item a').eq(i).addClass('selected');
            break;
        }
    }
}
/******************************************************/

//loader stron
$(document).ready(function() {
    $('<div id="loading" style="position:absolute;margin:0;paddind:0;right:0;top:8px"><img src="resource/loader.gif" /></div>')
        .insertBefore('#wrapper')
        .ajaxStart(function() {
            $(this).show();
            $('.menu-item a').removeClass().addClass('menu-item');
        }).ajaxStop(function() {
            $(this).fadeOut("slow");
        });
});

//ukrywanie bota
$(document).ready(function() {
    var $firstPara = $('#bot');
    $firstPara.show();
    $('#hidebot').click(function() {
        if ($firstPara.is(':hidden')) {
            $firstPara.show();
            $('#hidebotimg').attr({
                'src': 'resource/bullet_toggle_minus.png',
                'alt': '+'
            });
            $('#hidetext').text('');
        } else {
            $firstPara.hide();
            $('#hidebotimg').attr({
                'src': 'resource/bullet_toggle_plus.png',
                'alt': '-'
            });
            $('#hidetext').text("wirtualny doradca");
        }
        return false;
    });
});

function showBot() {
    /*
    var swf = new SWFObject("bot/avatar.swf", "bot", "220", "555", "9", "#142334");
    swf.addVariable("avatarPath", "avatar.xml");

    swf.addParam("menu", "false");
    swf.addParam("wmode", "window");
    swf.write("bot");
    */
    var swf = new SWFObject("bot/loader.swf", "bot", "220", "555", "9", "#142334");
    swf.addVariable("configfile", "bot/avatar.xml");
    swf.addVariable("skin", "bot/avatar.swf");
    swf.addVariable("engine", "bot/engine.swf");

    swf.addParam("menu", "false");
    swf.addParam("wmode", "window");
    swf.write("bot");
}

