

var AUTO_SCROLL_TABS = new Array();
var AUTO_SCROLL_TABS_DELAY = 4000;

var TEXT_ON_IMAGE_LIST = new Array();
var CSS_SPIDER_ITEMS = 'spider-items';
var CSS_SPIDER_ITEM = 'spider-item';


function scrollAllTabs() {
    for (var i=0; i<AUTO_SCROLL_TABS.length; i++) {
        var modConfId = AUTO_SCROLL_TABS[i];
        if (modConfId > 0) scrollTab(modConfId);
    }
}

function startTabScroll(modConfId) {
    if (modConfId > 0) AUTO_SCROLL_TABS.push(modConfId);
}

function showTab(modConfId, contentId) {

    if ((modConfId < 1) || (contentId < 1)) return;

    hideTabs(modConfId);

    var id = "spider-tab-title-" + modConfId + "-" + contentId;
    var o = document.getElementById(id);
    if (!o) return;
    o.className = "spider-selected";

    var id = "spider-tab-" + modConfId + "-" + contentId;
    var o = document.getElementById(id);
    if (!o) return;
    o.style.display = "block";
}

function hideTabs(modConfId) {
    if (modConfId < 1) return;
    var id = "spider-tabs-" + modConfId;
    var ul = document.getElementById(id);
    if (!ul) return;
    for (var i=0; i<ul.childNodes.length; i++) {
        var o = ul.childNodes.item(i);
        if (!o) continue;
        o.className = "";
        if (!o.id) continue;
        id = o.id;
        id = id.substr(id.lastIndexOf("-")+1);
        if (!(id > 0)) continue;
        id = "spider-tab-" + modConfId + "-" + id;
        o = document.getElementById(id);
        if (!o) continue;
        o.style.display = "none";
    }
}

function scrollTab(modConfId) {

    if (modConfId < 1) return;

    var selectedNumber = 0;
    var id = "spider-tabs-" + modConfId;
    var ul = document.getElementById(id);
    if (!ul) return;
    for (var i=0; i<ul.childNodes.length; i++) {
        var o = ul.childNodes.item(i);
        if (!o || !o.id) continue;
        id = o.id;
        id = id.substr(id.lastIndexOf("-")+1);
        if (!(id > 0)) continue;
        if (o.className == "spider-selected") {
            selectedNumber = i;
        }
    }

    selectedNumber++;
    if (selectedNumber >= ul.childNodes.length) selectedNumber = 0;

    var id = ul.childNodes.item(selectedNumber).id;
    id = id.substr(id.lastIndexOf("-")+1);

    hideTabs();
    showTab(modConfId, id);

}

function stopTabScroll(modConfId) {
    for (var i=0; i<AUTO_SCROLL_TABS.length; i++) {
        if (AUTO_SCROLL_TABS[i] == modConfId) {
            AUTO_SCROLL_TABS[i] = 0;
        }
    }
}

function emailFormFocus(emailFormId) {
    if (!document.forms[emailFormId]) return true;
    if (document.forms[emailFormId].email.value == document.forms[emailFormId].dt.value) {
        document.forms[emailFormId].email.value = "";
    }
}

function emailFormChange(emailFormId) {
    if (!document.forms[emailFormId]) return true;
    if (document.forms[emailFormId].email.value.length > 0) return true;
    document.forms[emailFormId].email.value = document.forms[emailFormId].dt.value;
}

function textOnImage() {

    if (!TEXT_ON_IMAGE_LIST || (TEXT_ON_IMAGE_LIST.length == 0)) return;

    for (var i=0; i<TEXT_ON_IMAGE_LIST.length; i++) {
        var data = TEXT_ON_IMAGE_LIST[i];
        textOnImageApply(
            data.id,
            data.type,
            data.text_pos_h,
            data.text_pos_v,
            data.text_pos_h_offset,
            data.text_pos_v_offset,
            data.text_color,
            data.text_title_color,
            data.text_bg_color,
            data.text_opacity,
            data.text_font_size,
            data.text_title_font_size
            );
    }
}

function textOnImageApply(
    id,
    type,
    text_pos_h,
    text_pos_v,
    text_pos_h_offset,
    text_pos_v_offset,
    text_color,
    text_title_color,
    text_bg_color,
    text_opacity,
    text_font_size,
    text_title_font_size
) {

    $('#' + CSS_SPIDER_ITEMS + '-' + id).css('position', 'relative');

    $('#' + CSS_SPIDER_ITEMS + '-' + id + ' .' + CSS_SPIDER_ITEM + ':first').css('position', 'absolute');
    $('#' + CSS_SPIDER_ITEMS + '-' + id + ' .' + CSS_SPIDER_ITEM + ':first').css('top', '0');
    $('#' + CSS_SPIDER_ITEMS + '-' + id + ' .' + CSS_SPIDER_ITEM + ':first').css('left', '0');

    $('#' + CSS_SPIDER_ITEMS + '-' + id + ' img').css('display', 'none');

    if (type == 'cc') {
        $('#' + CSS_SPIDER_ITEMS + '-' + id + ' img:parent').css('display', 'none');
        $.each($('#' + CSS_SPIDER_ITEMS + '-' + id + ' .' + CSS_SPIDER_ITEM + ''), function(i, o) {
            var img = $(o).children('span').children('a').children('img');
            if (!img.attr("src")) img = $(o).children('span').children('img');
            if (!img.attr("src")) return;
            $(o).css('background-image', 'url(' + img.attr('src') + ')')
                .css('height', $(o).parent().css('height'))
                .css('width', $(o).parent().css('width'))
                ;
       });
    } else if (type == 'rss') {
       $.each($('#' + CSS_SPIDER_ITEMS + '-' + id + ' .' + CSS_SPIDER_ITEM + ''), function(i, o) {
            $(o).css('background-image', 'url(' + $(o).children('img').attr('src') + ')')
                .css('height', $(o).parent().css('height'))
                .css('width', $(o).parent().css('width'))
                ;
       });
    }

   $('#' + CSS_SPIDER_ITEMS + '-' + id + ' .' + CSS_SPIDER_ITEM + ' span')
        .css('position', 'absolute')
        .css('display', 'block')
        .css('max-width', '100%')
        .css(text_pos_h, text_pos_h_offset + 'px')
        .css(text_pos_v, text_pos_v_offset + 'px')
        .css('padding', '3px')
        .css('background-color', text_bg_color)
        .css('color', text_color)
        .css('opacity', text_opacity)
        ;

   if (text_font_size > 0) {
       $('#' + CSS_SPIDER_ITEMS + '-' + id + ' .' + CSS_SPIDER_ITEM + ' span')
            .css('font-size', text_font_size + 'px');
   }

   $('#' + CSS_SPIDER_ITEMS + '-' + id + ' .' + CSS_SPIDER_ITEM + '')
        .css('max-width', $('#' + CSS_SPIDER_ITEMS + '-' + id + ' .' + CSS_SPIDER_ITEM + '').parent().css('width'))
        .css('margin', 0)
        .css('padding-top', 0)
        .css('padding-bottom', 0)
        ;

   $('#' + CSS_SPIDER_ITEMS + '-' + id + ' .' + CSS_SPIDER_ITEM + ' h4, #' + CSS_SPIDER_ITEMS + '-' + id + ' .' + CSS_SPIDER_ITEM + ' h4 a')
        .css('color', text_title_color)
        ;

   if (text_title_font_size > 0) {
       $('#' + CSS_SPIDER_ITEMS + '-' + id + ' .' + CSS_SPIDER_ITEM + ' h4, #' + CSS_SPIDER_ITEMS + '-' + id + ' .' + CSS_SPIDER_ITEM + ' h4 a')
       .css('font-size', text_title_font_size + 'px')
       ;
   }
}

$(document).ready(textOnImage);





if (AUTO_SCROLL_TABS_DELAY > 0) setInterval(scrollAllTabs, AUTO_SCROLL_TABS_DELAY);

