var status;
var status2;
var id;
var il;
var il2;
var il3;
var diff;
var flashMovie;
var img = new Array(6);
for(var i =0; i <= 5; i++)
{
img[i] = new Image;
var j = (i+1) + "";
img[i].src = "/cokelivefreshnoise/_images/clfn2010/etap"+j+".gif";
//alert("Src obrazka nr "+i+": "+img[i].src);
}

function openpopup(url) {

		var theURL=url;
		var winName='popup';
		var width=500;
		var height=580;
		var topY=(screen.height-height)/2;
		var leftX=(screen.width-width)/2;
		var features='innerWidth=' + width+',innerHeight='+height+',width=' + width+',height='+height+',top='+topY+',left='+leftX+',resizable=0,srollbars=0';

	
	    var popup=window.open(theURL,winName,features);
		popup.focus();
}
function setflashvideo(link) {
    var flashvars = {
        videoUrl: link
    };
    var params = {
        menu: "false",
        scale: "noScale",
        allowFullscreen: "true",
        allowScriptAccess: "always",
        bgcolor: "#333333"
    };

    var attributes = {
        id: "VideoPlayer",
        wmode: "window"
    };
    swfobject.embedSWF("/cokelivefreshnoise/_files/clfn2010/VideoPlayer.swf", "flashcontent", "640", "400", "10.0.0", "expressInstall.swf", flashvars, params, attributes);
}
function getFlashMovieObject(movieName) {
    return document.getElementById(movieName);
}

function activateVp() {
    flashMovie = getFlashMovieObject("VideoPlayer");
    flashMovie.activateVideo();
}

function deactivateVp() {
    flashMovie = getFlashMovieObject("VideoPlayer");
    flashMovie.deactivateVideo();
    $(flashMovie).replaceWith('<div id="flashcontent"></div>');
}

window.onresize = function(){
    var ww=$('body').width();
    if (ww < 960) ww = 960;
    $('#wrapper').css("width", ww);
}
function setwrapper() {
    var w = $('#wrapper').width();
    if (w < 960) w = 960;
    $('#wrapper').css("width", w);
}
function setloginlist() {
    il = $('.topmenu_favartist').length;

    if (il <= 5) {
        il2 = il * 25;
        $('.topmenu_favartists .first').css("border-top", "none");
    }
    else {
        il2 = 126;
        $('.topmenu_afterlogin .updown').addClass('updownactive');
    }
    il2 = il2 + "px";
    $('.topmenu_favartists_cont').css("height", il2);
}
function logindown() {
    var max = 125 - il * 25;
    var x = $('.topmenu_favartists').css("top").split("px");
    if (x[0] > max) {
        var y = x[0] - 1 + "px";
        $('.topmenu_favartists').css("top", y);
    }
}
function loginup() {
    var max = 0;
    var x = $('.topmenu_favartists').css("top");
    if (x != "0px") {
        x = x.split("px");
        if (x[0] < 0) {
            var y = parseInt(x[0]) + 1;
            y = y + "px";
        }
        $('.topmenu_favartists').css("top", y);
    }
}

function setvideolist() {
    il3 = $('.video_item').length;
    if (il3 == 1) {$('#right .video .go').css("color","black").css("cursor","default");}
    il3 = il3 * 297;
    diff = 297 - il3;
    il3 = il3 + "px";
    $('.video_items').css("width", il3);
    
}
function setpress() {
    $('.prasoweUl li').each(function() {
        var wys = $(this).height();
        if (wys < 30)
            $(this).css("height", "30px");
    });
}

function pokazdodawanie() {
    $('#onenews_comments .add_comment').siblings().filter('.add').toggle();
    var plus = $('#onenews_comments .add_comment').children().filter('.plus');
    if (plus.text() == "[+]")
        plus.html("[&ndash;]");
    else
        plus.text("[+]");
    return (false);
}

$(document).ready(function() {
    setwrapper();
    if ($(".art_tab").hasClass("active")) {
        $(".tabs").css("background-image", "url('_images/clfn2010/tabs1.gif')");
        $("#jury_main").hide();
        $(".artistslist").show();
        $('.see_others').show();
    }
    else if ($(".jury_tab").hasClass("active")) {
        $(".tabs").css("background-image", "url('_images/clfn2010/tabs2.gif')");
        $(".artistslist").hide();
        $("#jury_main").show();
        $('.see_others').hide();
    }



    function zmientabki() {
        var bg = $(".tabs").css("background-image");
        var bg2 = bg.split("tabs");
        var bg3 = bg2[1].split(".");
        if (bg3[0] == "1") bg3[0] = "2";
        else bg3[0] = "1";
        var back = bg2[0] + "tabs" + bg3[0] + "." + bg3[1];
        $(".tabs").css("background-image", back);
        return (false);
    }

    $('.white_cont .tabs a').click(function() {
        if (!$(this).hasClass("active")) {
            $('.white_cont .tabs a').removeClass("active");
            $(this).addClass("active");
            zmientabki();
            $('#jury_main').toggle();
            $('.artistslist').toggle();
            $('.see_others').toggle();
        }
        return (false);
    });


    setloginlist();
    $('.topmenu_fav').click(function() {
        $('.topmenu_favartists_cont').slideToggle();
        $('.topmenu_fav img').toggle();
        $('.topmenu_afterlogin .updownactive').toggle();
        return (false);
    });
    $('.topmenu_afterlogin .down').hover(function() { id = setInterval('logindown();', 20); },
   function() { clearInterval(id); });
    $('.topmenu_afterlogin .up').hover(function() { id = setInterval('loginup();', 20); },
   function() { clearInterval(id); });

    setvideolist();
    var test = 1;
    $('#right .video .goright').click(function() {
        if (test == 1) {
            test = 0;
            var x = $('.video_items').css("left").split("px");
            if (x[0] > diff) {
                var y = x[0] - 297 + "px";
                $('.video_items').animate({ left: y }, { complete: function() { test = 1; } });
            }
            else
                test = 1;
        }

        return (false);
    });
    $('#right .video .goleft').click(function() {
        if (test == 1) {
            test = 0;
            var x1 = $('.video_items').css("left").split("px");
            if (x1[0] < 0) {
                var y = parseInt(x1[0]) + 297;
                y = y + "px";
                $('.video_items').animate({ left: y }, { complete: function() { test = 1; } });
            }
            else
                test = 1;
        }
        return (false);
    });
    setpress();

    $('.filmPlay').click(function() {
        scroll(0,0);
        var rel = $(this).attr("rel");
        setflashvideo(rel);
        var h = $('#content').height();
        h += 231;
        h += "px";
        $('#filmPopupWrap').removeClass('hide').css("height", h);
        $('#right').hide();
        $('.zaslepkaright').show();
        setTimeout('activateVp()', 500);
        return false;
    });

    $('#close').click(function() {
        $('#filmPopupWrap').addClass('hide');
        $('#right').show();
        $('.zaslepkaright').hide();
        deactivateVp();
    });

    return (false);
});                                  