jQuery.noConflict();
var sphour;
var spminute;
var spsecond;
var rels, relcon, relconnum;
function update_chat()
{
    close = getCookie('chat_close');
    if(close==1)
    {
        jQuery("#chat_block").hide();
        jQuery("#chat_resize").html("[показать]");
    }
    else
    {
        close = 1; 
        jQuery("#chat_block").show();
        jQuery("#chat_resize").html("[скрыть]");
    }
}

jQuery(function(){
    jQuery("#chat_resize").click(function()
    {
        close = getCookie('chat_close');
        if(close==1)
        {
            close = 0;
        }
        else
        {
            close = 1; 
        }
        setCookie('chat_close',close,new Date(2018, 1, 1), '/', 'www.pslan.com', '');
        update_chat();
        return false;
    });
    update_chat();
    sphour = jQuery("#chour");
    spminute = jQuery("#cminute");
    spsecond = jQuery("#csecond");
    sphour.text(makedigit(chour));
    spminute.text(makedigit(cminute));
    spsecond.text(makedigit(csecond));
    setInterval ( "updateClock()", 995 );
    //setInterval ( "updateNews()", 5000 );
    relcon = jQuery(".relcon");
    relconnum = jQuery(".relcon").length;
    for(i=0;i<relconnum;i++)
    {
        tmp = relcon[i].id.substr(0,3);
        updateRel[i] = new Array();
        updateRel[i][0] = true;
        updateRel[i][1] = 1;
        updateRel[i][2] = tmp;
    }
    rels = jQuery(".relprew");
    setInterval ( "updateRels()", 10000 );
    jQuery(".forclick").click(function(e){
        userNewsClicked(e);
    });
    rels.hover(
        function (e) {
            showRelTitle(e);
        }, 
        function () {
        
        }
        );

        

});

var updateRel = new Array();

function lotoremovemark(el)
{
    el.target.style.background = "none";
}
function lotoaddmark(el)
{
    el.target.style.background = "url('/themes/pslan/images/loto/cross.png')";
//el.togleClass('selected');
}
function lotoupdatenums()
{
    var result = [];
    lotonums = 0;
    for(var i=1; i<=25; i++)
    {
        if(lotonums_array[i] != 0)
        {
            result.push(i);
            lotonums++;
        }
    }
    jQuery('#ticket-numbers').val(result.join('-'));
}
function lotoclear()
{
    for(var i=1; i<=25; i++)
    {
        lotonums_array[i] = 0;
    }
    jQuery('#loto-ticket span').css('background', 'none');
    lotoupdatenums();
}
function lotoclick(e)
{
    var id = e.target.id + '';
    var id_num = parseInt(id.substr(7));
    var element = jQuery(e);

    if(lotonums_array[id_num] != 0)
    {
        lotoremovemark(e);
        lotonums_array[id_num] = 0;
        lotoupdatenums();
    }
    else if(lotonums < 5)
    {
        lotoaddmark(e);
        lotonums_array[id_num] = 1;
        lotoupdatenums();
    }
}

function spoilerMe(object)
{
    jQuery(object).parent().find(".spoilerText:first").toggle();
    url = jQuery(object).find("img:first");
    if(url.attr('src')=='pic/minus.gif')
    {
        url.attr('src','pic/plus.gif');
    }
    else
    {
        url.attr('src','pic/minus.gif');
    }
}

function inputPlaceholder (input, color, size) {

    if (!input) return null;

    // Do nothing if placeholder supported by the browser (Webkit, Firefox 3.7)
    if (input.placeholder && 'placeholder' in document.createElement(input.tagName)) return input;

    color = color || '#AAA';
    size = size || '10px';
    var default_color = input.style.color;
    var default_size = input.style.fontSize;
    var placeholder = input.getAttribute('placeholder');

    if (input.value === '' || input.value == placeholder) {
        input.value = placeholder;
        input.style.color = color;
        input.style.fontSize = size;
        input.setAttribute('data-placeholder-visible', 'true');
    }

    var add_event = /*@cc_on'attachEvent'||@*/'addEventListener';

    input[add_event](/*@cc_on'on'+@*/'focus', function(){
        input.style.color = default_color;
        input.style.fontSize = default_size;
        if (input.getAttribute('data-placeholder-visible')) {
            input.setAttribute('data-placeholder-visible', '');
            input.value = '';
        }
    }, false);

    input[add_event](/*@cc_on'on'+@*/'blur', function(){
        if (input.value === '') {
            input.setAttribute('data-placeholder-visible', 'true');
            input.value = placeholder;
            input.style.color = color;
            input.style.fontSize = size;
        } else {
            input.style.color = default_color;
            input.style.fontSize = default_size;
            input.setAttribute('data-placeholder-visible', '');
        }
    }, false);

    input.form && input.form[add_event](/*@cc_on'on'+@*/'submit', function(){
        if (input.getAttribute('data-placeholder-visible')) {
            input.value = '';
        }
    }, false);

    return input;
}


function showRelTitle(e)
{
    clickedId = e.target.id;
    clickedId = clickedId.substr(0, 3);
    jQuery("#"+clickedId+"_tit").text(jQuery(e.target).attr("title"));
	
}
function showRealeseDo(pref, id)
{
    jQuery("#"+pref+"_tit").text("");
    changeContent(jQuery("#"+pref+"_con"), jQuery("#"+pref+"_"+id));
    jQuery(".relprew").hover(
        function (e) {
            showRelTitle(e);
        }, 
        function () {
        
        }
        );
}
function showRealese(pref, id)
{
    for(i=0;i<relconnum;i++)
    {
        if(updateRel[i][2]==pref)
        {
            updateRel[i][0] = false;
        }
    }
    showRealeseDo(pref, id);
}
//Нажатие на новость
var currentNewsCont = 1;
var animateNews = true;
function updateRels()
{
    for(i=0;i<relconnum;i++)
    {
        if(updateRel[i][0])
        {
            if(updateRel[i][1]==4)
                next = 1
            else
                next = updateRel[i][1] + 1;
            showRealeseDo(updateRel[i][2],next);
            updateRel[i][1] = next;
        }
    }
}
function updateNews()
{
    if(animateNews)
    {
        if(currentNewsCont==3)
            next = 1
        else
            next = currentNewsCont + 1;
        showNews(next);
    }
}
function userNewsClicked(e)
{
    clickedId = e.originalTarget.id;
    if(clickedId.substr(0, 5)=='arit_')
    {
        animateNews = false;
        clickedId = clickedId.substr(5, 5);
        contaner = jQuery("#arbl_"+currentNewsCont);
        article = jQuery("#arte_"+clickedId);
        changeContent(contaner, article);
        jQuery(e.currentTarget).find("a").animate({
            fontSize: "13px"
        }, 100);
        jQuery(e.originalTarget).animate({
            fontSize: "15px"
        }, 400);
		
    }
	
}
function showNews(id)
{
    changeContent(jQuery("#news"), jQuery("#news_"+id));
    jQuery(".forclick").click(function(e){
        userNewsClicked(e);
    });
    currentNewsCont = id;
}
function votetor(num)
{
    jQuery("#votebon").val(num);
    jQuery("#votedaemoon").submit();
}
function changeContent(cont, text)
{
    cont.animate({
        opacity: 0
    }, 100).html(text.html()).animate({
        opacity: 1
    }, 500);
}
function changeSimple(cont, text)
{
    cont.html(text.html());
}
function updateClock()
{
    csecond += 1;
    if(csecond == 60)
    {
        csecond = 0;
        cminute += 1;
        if(cminute == 60)
        {
            cminute = 0;
            chour += 1;
            if(chour==24)
            {
                chour = 0;
            }
        }
		
    }
    sphour.text(makedigit(chour));
    spminute.text(makedigit(cminute));
    spsecond.text(makedigit(csecond));
}
function makedigit(number)
{
    if(number < 10)
        return "0"+number;
    else
        return number;
}
function winop()
{
    windop = window.open("http://pslan.com/copyright.php","mywin","height=500,width=800");
}
function wincl()
{
    windop.close();
}

jQuery.noConflict()

var ddaccordion={
	
    contentclassname:{}, //object to store corresponding contentclass name based on headerclass

    expandone:function(headerclass, selected){ //PUBLIC function to expand a particular header
        this.toggleone(headerclass, selected, "expand")
    },

    collapseone:function(headerclass, selected){ //PUBLIC function to collapse a particular header
        this.toggleone(headerclass, selected, "collapse")
    },

    expandall:function(headerclass){ //PUBLIC function to expand all headers based on their shared CSS classname
        var $=jQuery
        var $headers=$('.'+headerclass)
        $('.'+this.contentclassname[headerclass]+':hidden').each(function(){
            $headers.eq(parseInt($(this).attr('contentindex'))).click()
        })
    },

    collapseall:function(headerclass){ //PUBLIC function to collapse all headers based on their shared CSS classname
        var $=jQuery
        var $headers=$('.'+headerclass)
        $('.'+this.contentclassname[headerclass]+':visible').each(function(){
            $headers.eq(parseInt($(this).attr('contentindex'))).click()
        })
    },

    toggleone:function(headerclass, selected, optstate){ //PUBLIC function to expand/ collapse a particular header
        var $=jQuery
        var $targetHeader=$('.'+headerclass).eq(selected)
        var $subcontent=$('.'+this.contentclassname[headerclass]).eq(selected)
        if (typeof optstate=="undefined" || optstate=="expand" && $subcontent.is(":hidden") || optstate=="collapse" && $subcontent.is(":visible"))
            $targetHeader.click()
    },

    expandit:function($targetHeader, $targetContent, config, isclicked){
        $targetContent.slideDown(config.animatespeed, function(){
            config.onopenclose($targetHeader.get(0), parseInt($targetHeader.attr('headerindex')), $targetContent.css('display'), isclicked)
        })
        this.transformHeader($targetHeader, config, "expand")
    },

    collapseit:function($targetHeader, $targetContent, config, isclicked){
        $targetContent.slideUp(config.animatespeed, function(){
            config.onopenclose($targetHeader.get(0), parseInt($targetHeader.attr('headerindex')), $targetContent.css('display'), isclicked)
        })
        this.transformHeader($targetHeader, config, "collapse")
    },

    transformHeader:function($targetHeader, config, state){
        $targetHeader.addClass((state=="expand")? config.cssclass.expand : config.cssclass.collapse) //alternate btw "expand" and "collapse" CSS classes
        .removeClass((state=="expand")? config.cssclass.collapse : config.cssclass.expand)
        if (config.htmlsetting.location=='src'){ //Change header image (assuming header is an image)?
            $targetHeader=($targetHeader.is("img"))? $targetHeader : $targetHeader.find('img').eq(0) //Set target to either header itself, or first image within header
            $targetHeader.attr('src', (state=="expand")? config.htmlsetting.expand : config.htmlsetting.collapse) //change header image
        }
        else if (config.htmlsetting.location=="prefix") //if change "prefix" HTML, locate dynamically added ".accordprefix" span tag and change it
            $targetHeader.find('.accordprefix').html((state=="expand")? config.htmlsetting.expand : config.htmlsetting.collapse)
        else if (config.htmlsetting.location=="suffix")
            $targetHeader.find('.accordsuffix').html((state=="expand")? config.htmlsetting.expand : config.htmlsetting.collapse)
    },

    urlparamselect:function(headerclass){
        var result=window.location.search.match(new RegExp(headerclass+"=((\\d+)(,(\\d+))*)", "i")) //check for "?headerclass=2,3,4" in URL
        if (result!=null)
            result=RegExp.$1.split(',')
        return result //returns null, [index], or [index1,index2,etc], where index are the desired selected header indices
    },

    getCookie:function(Name){ 
        var re=new RegExp(Name+"=[^;]+", "i") //construct RE to search for target name/value pair
        if (document.cookie.match(re)) //if cookie found
            return document.cookie.match(re)[0].split("=")[1] //return its value
        return null
    },

    setCookie:function(name, value){
        document.cookie = name + "=" + value
    },

    init:function(config){
        document.write('<style type="text/css">\n')
        document.write('.'+config.contentclass+'{display: none}\n') //generate CSS to hide contents
        document.write('<\/style>')
        jQuery(document).ready(function($){
            ddaccordion.urlparamselect(config.headerclass)
            var persistedheaders=ddaccordion.getCookie(config.headerclass)
            ddaccordion.contentclassname[config.headerclass]=config.contentclass //remember contentclass name based on headerclass
            config.cssclass={
                collapse: config.toggleclass[0], 
                expand: config.toggleclass[1]
            } //store expand and contract CSS classes as object properties
            config.htmlsetting={
                location: config.togglehtml[0], 
                collapse: config.togglehtml[1], 
                expand: config.togglehtml[2]
            } //store HTML settings as object properties
            config.oninit=(typeof config.oninit=="undefined")? function(){} : config.oninit //attach custom "oninit" event handler
            config.onopenclose=(typeof config.onopenclose=="undefined")? function(){} : config.onopenclose //attach custom "onopenclose" event handler
            var lastexpanded={} //object to hold reference to last expanded header and content (jquery objects)
            var expandedindices=ddaccordion.urlparamselect(config.headerclass) || ((config.persiststate && persistedheaders!=null)? persistedheaders : config.defaultexpanded)
            if (typeof expandedindices=='string') //test for valid cookie ('string'), invalid being null or 1st page load
                expandedindices=expandedindices.replace(/c/ig, '').split(',') //if valid, change to array value
            var $subcontents=$('.'+config["contentclass"])
            if (!(expandedindices instanceof Array)) //check for invalid expandedindices value
                expandedindices=[]
            if (config["collapseprev"] && expandedindices.length>1)
                expandedindices=[expandedindices.pop()] //return last array element as an array (for sake of jQuery.inArray())
            $('.'+config["headerclass"]).each(function(index){ //loop through all headers
                if (/(prefix)|(suffix)/i.test(config.htmlsetting.location) && $(this).html()!=""){ //add a SPAN element to header depending on user setting and if header is a container tag
                    $('<span class="accordprefix"></span>').prependTo(this)
                    $('<span class="accordsuffix"></span>').appendTo(this)
                }
                $(this).attr('headerindex', index+'h') //store position of this header relative to its peers
                $subcontents.eq(index).attr('contentindex', index+'c') //store position of this content relative to its peers
                var $subcontent=$subcontents.eq(index)
                if (jQuery.inArray(index, expandedindices)!=-1){ //check for headers that should be expanded automatically
                    if (config.animatedefault==false)
                        $subcontent.show()
                    ddaccordion.expandit($(this), $subcontent, config, false) //Last Boolean value sets 'isclicked' parameter
                    lastexpanded={
                        $header:$(this), 
                        $content:$subcontent
                    }
                }  //end check
                else{
                    $subcontent.hide()
                    config.onopenclose($(this).get(0), parseInt($(this).attr('headerindex')), $subcontent.css('display'), false) //Last Boolean value sets 'isclicked' parameter
                    ddaccordion.transformHeader($(this), config, "collapse")
                }
            })
            $('.'+config["headerclass"]).click(function(){ //assign behavior when headers are clicked on
                var $subcontent=$subcontents.eq(parseInt($(this).attr('headerindex'))) //get subcontent that should be expanded/collapsed
                if ($subcontent.css('display')=="none"){
                    ddaccordion.expandit($(this), $subcontent, config, true) //Last Boolean value sets 'isclicked' parameter
                    if (config["collapseprev"] && lastexpanded.$header && $(this).get(0)!=lastexpanded.$header.get(0)){ //collapse previous content?
                        ddaccordion.collapseit(lastexpanded.$header, lastexpanded.$content, config, true) //Last Boolean value sets 'isclicked' parameter
                    }
                    lastexpanded={
                        $header:$(this), 
                        $content:$subcontent
                    }
                }
                else{
                    ddaccordion.collapseit($(this), $subcontent, config, true) //Last Boolean value sets 'isclicked' parameter
                }
                return false
            })
            config.oninit($('.'+config["headerclass"]).get(), expandedindices)
            $(window).bind('unload', function(){ //clean up and persist on page unload
                $('.'+config["headerclass"]).unbind('click')
                var expandedindices=[]
                $('.'+config["contentclass"]+":visible").each(function(index){ //get indices of expanded headers
                    expandedindices.push($(this).attr('contentindex'))
                })
                if (config.persiststate==true){ //persist state?
                    expandedindices=(expandedindices.length==0)? '-1c' : expandedindices //No contents expanded, indicate that with dummy '-1c' value?
                    ddaccordion.setCookie(config.headerclass, expandedindices)
                }
            })
        })
    }
}
//Tabs
//----------------------------------
function setCookie(name, value, expires, path, domain, secure)
{
    var curCookie = name + "=" + escape(value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
    document.cookie = curCookie;
}

function getCookie(name)
{
    var prefix = name + "=";
    var cookieStartIndex = document.cookie.indexOf(prefix);
    if (cookieStartIndex == -1)
        return null;
    var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);
    if (cookieEndIndex == -1)
        cookieEndIndex = document.cookie.length;
    return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}


function makebatch(name, type)
{
    var i;
    for(i=1;i<30;i++)
    {
        if(document.getElementById(name+'_'+i))
        {
            document.getElementById(name+'_'+i).style.display = type;
        }
    }
}
function showpics()
{
    makebatch('catpic','none');
    makebatch('relpic','block');
    setCookie('browse','relpic',new Date(2010, 1, 1), '/', 'pslan.com', '');
}
function hidepics()
{
    makebatch('catpic','block');
    makebatch('relpic','none');
    setCookie('browse','catpic',new Date(2010, 1, 1), '/', 'pslan.com', '');
}
function pslan_show_adv(url)
{
    var myDate = new Date ();
    var daybe = myDate.getDate(); 
    if(getCookie('adv') != daybe)
    {
//window.open(url, '', 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=600,height=600,left = 276,top = 132');
//window.focus();
//setCookie('adv',daybe,new Date(2010, 1, 1), '/', 'pslan.com', '');
// setCookie('advs',daybe,new Date(2010, 1, 1), '/', 'pslan.com', '');
//setCookie('adv',daybe,new Date(2010, 1, 1), '/', 'pslan.kiev.ua', '');
//setCookie('advs',daybe,new Date(2010, 1, 1), '/', 'pslan.kiev.ua', '');
//setCookie('showadv','1',new Date(2011, 1, 1), '/', 'pslan.kiev.ua', '');
}
}

var $j = jQuery.noConflict();

$j(document).ready(function() {

    $j('ul.tabs li').css('cursor', 'pointer');

    $j('ul.tabs.tabs1 li').click(function(){
        var thisClass = this.className.slice(0,2);
        $j('div.t1').hide();
        $j('div.t2').hide();
        $j('div.t3').hide();
        $j('div.t4').hide();
        $j('div.' + thisClass).show();
        $j('ul.tabs.tabs1 li').removeClass('tab-current');
        $j(this).addClass('tab-current');

    });

});

//Top menu start
$j(document).ready(function(){
    $j('#navmenu-h li').hover(
        function() {
            $j(this).addClass("active");
            $j(this).find('ul').show();
        },
        function() {
            $j(this).removeClass("active");        
            $j(this).find('ul').hide();
        }
        );
});
//end
//Colored Links
//-------------------------------------------
var rate = 20;

if (document.getElementById)
    window.onerror=new Function("return true")
var objActive;
var act = 0;
var elmH = 0;
var elmS = 128;
var elmV = 255;
var clrOrg;
var TimerID;

/*
if (document.all) {
    document.onmouseover = doRainbowAnchor;
    document.onmouseout = stopRainbowAnchor;
}
else if (document.getElementById) {
    document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
    document.onmouseover = Mozilla_doRainbowAnchor;
    document.onmouseout = Mozilla_stopRainbowAnchor;
}
function doRainbow(obj)
{
    if (act == 0) {
        act = 1;
        if (obj)
            objActive = obj;
        else
            objActive = event.srcElement;
        clrOrg = objActive.style.color;
        TimerID = setInterval("ChangeColor()",100);
    }
}
function stopRainbow()
{
    if (act) {
        objActive.style.color = clrOrg;
        clearInterval(TimerID);
        act = 0;
    }
}
function doRainbowAnchor()
{
    if (act == 0) {
        var obj = event.srcElement;
        while (obj.tagName != 'A' && obj.tagName != 'BODY') {
            obj = obj.parentElement;
            if (obj.tagName == 'A' || obj.tagName == 'BODY')
                break;
        }

        if (obj.tagName == 'A' && obj.href != '') {
            objActive = obj;
            act = 1;
            clrOrg = objActive.style.color;
            TimerID = setInterval("ChangeColor()",100);
        }
    }
}
function stopRainbowAnchor()
{
    if (act) {
        if (objActive.tagName == 'A') {
            objActive.style.color = clrOrg;
            clearInterval(TimerID);
            act = 0;
        }
    }
}
function Mozilla_doRainbowAnchor(e)
{
    if (act == 0) {
        obj = e.target;
        while (obj.nodeName != 'A' && obj.nodeName != 'BODY') {
            obj = obj.parentNode;
            if (obj.nodeName == 'A' || obj.nodeName == 'BODY')
                break;
        }

        if (obj.nodeName == 'A' && obj.href != '') {
            objActive = obj;
            act = 1;
            clrOrg = obj.style.color;
            TimerID = setInterval("ChangeColor()",100);
        }
    }
}
function Mozilla_stopRainbowAnchor(e)
{
    if (act) {
        if (objActive.nodeName == 'A') {
            objActive.style.color = clrOrg;
            clearInterval(TimerID);
            act = 0;
        }
    }
}*/
function ChangeColor()
{
    objActive.style.color = makeColor();
}
function makeColor()
{
    if (elmS == 0) {
        elmR = elmV;
        elmG = elmV;
        elmB = elmV;
    }
    else {
        t1 = elmV;
        t2 = (255 - elmS) * elmV / 255;
        t3 = elmH % 60;
        t3 = (t1 - t2) * t3 / 60;

        if (elmH < 60) {
            elmR = t1;
            elmB = t2;
            elmG = t2 + t3;
        }
        else if (elmH < 120) {
            elmG = t1;
            elmB = t2;
            elmR = t1 - t3;
        }
        else if (elmH < 180) {
            elmG = t1;
            elmR = t2;
            elmB = t2 + t3;
        }
        else if (elmH < 240) {
            elmB = t1;
            elmR = t2;
            elmG = t1 - t3;
        }
        else if (elmH < 300) {
            elmB = t1;
            elmG = t2;
            elmR = t2 + t3;
        }
        else if (elmH < 360) {
            elmR = t1;
            elmG = t2;
            elmB = t1 - t3;
        }
        else {
            elmR = 0;
            elmG = 0;
            elmB = 0;
        }
    }

    elmR = Math.floor(elmR).toString(16);
    elmG = Math.floor(elmG).toString(16);
    elmB = Math.floor(elmB).toString(16);
    if (elmR.length == 1)    elmR = "0" + elmR;
    if (elmG.length == 1)    elmG = "0" + elmG;
    if (elmB.length == 1)    elmB = "0" + elmB;

    elmH = elmH + rate;
    if (elmH >= 360)
        elmH = 0;

    return '#' + elmR + elmG + elmB;
}
//Highslide Init
//-------------------------------------
ddaccordion.init({
    headerclass: "expandable",
    contentclass: "categoryitems",
    collapseprev: true,
    defaultexpanded: [0],
    animatedefault: false,
    persiststate: true,
    toggleclass: ["", "openheader"],
    togglehtml: ["prefix", "", ""],
    animatespeed: "normal",
    oninit:function(headers, expandedindices){
    },
    onopenclose:function(header, index, state, isclicked){
    }
})
