/** Orion.lt, 2008. */

/* sIFR 3 */
if (typeof sIFR != "undefined") {
    var myriad_pro = { src: '/images/myriad_pro.swf' };
    sIFR.useStyleCheck = true;
    sIFR.activate(myriad_pro);
    sIFR.replace(myriad_pro, {
        selector: '#menu>ul>li>div>span>span',
        css: [
            '.sIFR-root { font-size: 16px; padding: 0; letter-spacing: -0.5}',
            'a { text-decoration: none;}',
            'a:link { color: #1e406d; }',
            'a:hover {color: #1e406d;}'
        ],
        wmode: 'transparent'
    });
    sIFR.replace(myriad_pro, {
        selector: '.credential h3',
        css: [
            '.sIFR-root { text-align: center; }'
        ]  
    });
    sIFR.replace(myriad_pro, {
        selector: 'h2,h3',
        css: [
            '.sIFR-root { font-size: 16px; padding: 0; color: #323232; letter-spacing: -0.5}'
        ]  
    });
    sIFR.replace(myriad_pro, {
        selector: '#content>h1',
        css: [
            '.sIFR-root { font-size: 20px; color: #323232; padding:0; line-height: 20px; letter-spacing: -0.5}'
        ]  
    });

    sIFR.replace(myriad_pro, {
        selector: '#contact h1',
        css: [
            '.sIFR-root { font-size: 20px; color: #838383; padding:0; line-height: 20px; letter-spacing: -0.5;}'
        ]  
    });
};

/** Ticker. */
function scrollTicker() {
    var ul = $('#ticker ul');
    var items = ul.children();
    if (items.length < 2) /* nothing to animate. */
        return;
    var offset = $(items[1]).offset().left - $(items[0]).offset().left;
    var speed = 40; /* msec/px */
    var duration = offset*speed;
    ul.animate({ left: "-="+offset }, duration, 'linear', scrollCallback);
}
function scrollCallback() {
    var ul = $('#ticker ul');
    var items = ul.children();
    $(items[0]).appendTo('#ticker ul');
    ul.css({left: 0});
    scrollTicker();
}

/** Banner list. */
window.BANNERS = [
    /* type (flash/image), duration, width, height, image_url, link */
]
window._current_banner = -1; /* So we get first on first nextBanner() call */
window._banner_timeout = null;

/** Switches to next banner. */
function nextBanner() {
    var nbanners = window.BANNERS.length;
    /** Not initialized, or no banner scriptlet on page. */
    if (!nbanners)
        return;
    switchBanner((window._current_banner+1) % nbanners, false);
}
/** Switcher to given banner. */
function switchBanner(index, manual) {
    window._current_banner = index;
    if (window._banner_timeout) {
        clearTimeout(window._banner_timeout);
    }
    var cur = window.BANNERS[index];
    /** Generate HTML. */
    var html = '';
    if (cur[0] == "flash") {
        var so = new SWFObject('@image_url', 'banner-flash-movie', '@width', '@height', '8', '#FFFFFF');
        so.addVariable('banner_url', '@url');
        html = so.getSWFHTML();
    } else {
        html = '<a href="@url"><img src="@image_url" width="@width" height="@height"/></a>'
    }
    html = html.replace(/@width/, cur[2]);
    html = html.replace(/@height/, cur[3]);
    html = html.replace(/@image_url/, cur[4]);
    html = html.replace(/@url/, cur[5]);
    $('#banner-container').html(html);
    /** Select title for active. */
    $('#banners a').removeClass('active');
    $('#banner-'+index+'-link').addClass('active');
    /** Timeout but for flash files. */
    window._banner_timeout = null;
    /** If swtiched manually, don't set timeout here. */
    if (!manual && cur[0] != "flash") {
        window._banner_timeout = setTimeout(nextBanner, cur[1]);
    }
}
/* Contact form activate/deactivate. */
function contactFormActivate() {
    $('#contact-form').addClass('active');
}
function contactFormDeactivate() {
    $('#contact-form').removeClass('active');    
}
$(document).ready(function() {
    /* Switch to first. */
    nextBanner();
    /* Setup links. */
    $('#banners span a').bind("click", function(e) {
        var text = $(this).text();
        switchBanner(parseInt(text) - 1, true);
        return false;
    })
    /* Contact form activation. */
    var ids = ['#contactform-name', '#contactform-email', '#contactform-notes'];
    for (var i = 0; i < ids.length; i++) {
        $(ids[i]).focus(contactFormActivate);
        $(ids[i]).blur(contactFormDeactivate);
    }
    /* Ticker with initial delay. */
    setTimeout(scrollTicker, 300);
    /* Tooltips. */
    $('#set1 *').tooltip();
    $('.Tips1').tooltip({
    	track: true,
    	delay: 0,
    	showURL: false,
    	showBody: " - ",
    	extraClass: "pretty1",
    	fixPNG: true,
    	opacity: 1,
    	top: 15,
    	left: -77
    });
    $('.Tips2').tooltip({
    	track: true,
    	delay: 0,
    	showURL: false,
    	showBody: " - ",
    	extraClass: "pretty2",
    	fixPNG: true,
    	opacity: 1,
    	top: -110,
    	left: -80
    });
    $('.Tips3').tooltip({
    	track: true,
    	delay: 0,
    	showURL: false,
    	showBody: " - ",
    	extraClass: "pretty3",
    	fixPNG: true,
    	opacity: 1,
    	top: -20,
    	left: -210
    });
});
