/**********************************\
 script: blink text
 author: unknown
 editor: vladots dot ru
 commnt: пришлось добавить побольше
         обработчиков для более
         симпотичной работы
 upgrade: jquery added
\**********************************/

// установка цвета текста
var sR = 3; // 1 цвет
var sG = 14;
var sB = 0;
var R = 255; // 2 цвет
var G = 255;
var B = 0;
var b = true; //

// обработчики
function h(color)
{
        hn = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A" ,"B", "C", "D", "E", "F");
        if(color<0){ return "00"; }
        else if(color>255){ return "FF"; }
        else
        {
                s = hn[Math.floor(color/16)] + hn[color%16];
                return s;
        }
}
function toH(red, green, blue){ return h(red) + h(green) + h(blue); }
function RGB(red, green, blue){ return toH(red, green, blue); }
function setBlinkColor(r, g, b)
{
        $("[@rel='blink']").each(function(i){ $(this).css("color", "#"+RGB(r, g, b)); })
}

function startChanging()
{
if(b==true)
        {
        if((R>256)||(G>256)||(B>256))
                {
                b=false;
                }
        R+=sR;G+=sG;B+=sB;
        }
else
        {
        if((R<0)||(G<0)||(B<0))
                {
                b=true;
                }
        R-=sR; G-=sG; B-=sB;
        }
setBlinkColor(R, G, B);
setTimeout("startChanging()", 5);
}

$(document).ready(function(){
        startChanging();

        // load index
        if ($("#ppintro").length){
                // create intro
                var so = new SWFObject("/ppintro.swf", "intro", "300", "500", "8", "#000000");
                so.addParam("wmode", "opaque");
                so.write("ppintro");
                // rules
                $("#rules").jqm({
                        onShow: function(hash){ hash.w.css('opacity',0.95).fadeIn(500); },
                        onHide: function(hash){ hash.w.fadeOut('2000', function(){ hash.o.remove(); }); }
                });
                // face control / dress code
                $("#fcdc").jqm({
                        onShow: function(hash){ hash.w.fadeIn(500); },
                        onHide: function(hash){ hash.w.fadeOut('2000', function(){ hash.o.remove(); }); }
                });
                // tmp info block
                $("#info").jqm({
                        onShow: function(hash){ hash.w.fadeIn(500); },
                        onHide: function(hash){ hash.w.fadeOut('2000', function(){ hash.o.remove(); }); }
                });
        }

        // start pic
        rotateBannerStart(1, 2, 2);
});

// special 4 birthday
function rotateBannerStart(num, ttl, time) {
        setTimeout('rotateBanner('+num+', '+ttl+', '+time+')', time * 1000);
}

function rotateBanner(num, ttl, time) {
        num_now = ((num+1) > ttl)? 1 : num+1;

        $("#birth > img").fadeOut(1000, function() {
                $(this).attr("src", "/promo/birthday_"+num_now+".jpg").fadeIn(1000, function(){
                        setTimeout('rotateBanner('+num_now+', '+ttl+', '+time+')', time * 1000);
                });
        });
}

// default forms
function openRules(){
        $("#rules").jqmShow();
        return false;
}
function openFcDc(){
        $("#fcdc").jqmShow();
        return false;
}
function openInfo(){
        $("#info").jqmShow();
}