﻿var clickid = "", curr = 0, next = 0, count = 0, rcount = 4, index = -1, rotaioncount = 0, DefatulTop = 50, MoveTop = 0;
$(document).ready(function() {
    $('div.parent > ul').hide()
    $('div.parent > div').click(function() { onClickMenu(this); });
    listImp(0); rotaioncount = $('#scroll_begin li').length; onClickMenu($("#" + $(".menuHeader").first().attr("id")));
   // $("#NewsLetterBody").Scroll({ line: 8, speed: 2000, timer: 2000 });
    $("#PictureBody").ImagesScroll({ line: 5, speed: 500, timer: 2000 });
    $("#Categorys > ul > li").each(function() { 
        var _this=$($(this).find("div.ItemsPicture")).find("a"),imgsrc="";
        imgsrc=$(_this).find("span").html();
        createImages(_this,imgsrc,0);
    });
});
function Category_onMouseOver(othis) { $(othis).css({ "backgroundColor": "#e1c07d", "color": "#000" }); }
function Category_onMouseOut(othis) { $(othis).css({ "backgroundColor": "", "color": "#FFF" }); }

var listImp = function(curr) { $('#scroll_begin li').eq(curr).css({ 'opacity': '0.5' }); }
var listImpdefault = function(last) { $('#scroll_begin li').eq(last).css({ 'opacity': '1' }); }
var scollRotation = function() {
    var vmintop = -((rotaioncount - rcount) * DefatulTop);
    var vMaxtop = (rotaioncount + 1 - rcount) * DefatulTop, vtop = curr + 1 - rcount;
    if (vtop > 0 && MoveTop > vmintop) { MoveTop = -(vtop * DefatulTop); $('#scroll_begin li').each(function() { $(this).animate({ "top": MoveTop.toString() + "px" }); }); }
    else if ((parseInt(0 - MoveTop) / DefatulTop) == (curr + 1)) { MoveTop = -curr * DefatulTop; $('#scroll_begin li').each(function() { $(this).animate({ "top": MoveTop.toString() + "px" }); }); }
    else if (curr == 0) { MoveTop = 0; $('#scroll_begin li').each(function() { $(this).animate({ "top": "0px" }); }); }
}
var imgPlay = function() {
    listImpdefault(curr); next = curr + 1;
    if (curr == count - 1) next = 0;
    play(next); listImp(next); curr++;
    if (curr > count - 1) { curr = 0; next = curr + 1; }
    scollRotation();
};

//Left Menu
var onClickMenu = function(othis) {
    var content = $(othis).next();
    var others = content.parent().siblings("div.parent").find("ul:visible");
    if (others.length) {
        others.slideUp('fast', function() {
            content.slideToggle('fast');
        });
    } else {
        content.slideToggle('fast');
    }
    $("div.CategoryMenu2").each(function() { if ($(othis).attr("id") != $(this).attr("id")) { $(this).removeClass("CategoryMenu2"); $(this).addClass("menuHeader"); } });
    if ($(othis).attr("class").indexOf("menuHeader") >= 0) { $(othis).removeClass("menuHeader"); $(othis).addClass("CategoryMenu2"); }
    else { $(othis).removeClass("CategoryMenu2"); $(othis).addClass("menuHeader"); }
    //    if (clickid == $(othis).attr("id")) {
    //        var h = parseInt($("#Middle").css("height").replace("px", ""));
    //        $("#Middle").css("height", h - 150);
    //    } else {
    //        $("#Middle").css("height", (content.find("li").length * 25 + 150) + "px");
    //    }
    if (content.find("li").length > 0) {
        clickid = $(othis).attr("id");
    }
}
var categoryMenu_mouserover = function(othis) {
    var oldurl = $(othis).css("backgroundImage"), url = "";
    if ($("#CategoryMenu2 > img").attr("src").indexOf("url") >= 0) { url = $("#CategoryMenu2 > img").attr("src"); }
    else { url = "url('" + $("#CategoryMenu2 > img").attr("src") + "')"; }
    $(othis).css("backgroundImage", url);
    $("#CategoryMenu2 > img").attr("src", oldurl)
}
var categoryMenu_mouserout = function(othis) {
    var oldurl = $(othis).css("backgroundImage");
    $(othis).css("backgroundImage", $("#CategoryMenu2 > img").attr("src"));
    $("#CategoryMenu2 > img").attr("src", oldurl)
}
