// JavaScript Document
var titleIndex;
var titleNum;
$(document).ready(function(){
    $(".why ul li").each(function(){
        $(this).hover(function(){
            $(".why ul li").each(function(){
                if ($(this).hasClass("checked")) 
                    $(this).removeClass("checked");
            })
            $(this).addClass("checked");
            $(".why ul li").each(function(){
                $("#" + $(this).text().toLowerCase()).css({
                    display: "none"
                });
            })
            $("#" + $(this).text().toLowerCase()).css({
                display: "block"
            });
        })
    });
    $(".tab li").each(function(){
        $(this).hover(function(){
            $(".tab li").each(function(){
                if ($(this).hasClass("checked")) 
                    $(this).removeClass("checked");
            })
            $(this).addClass("checked");
            $(".tab li").each(function(){
                $("." + $(this).text().toLowerCase().replace(" ", "")).css({
                    display: "none"
                });
            })
            $("." + $(this).text().toLowerCase().replace(" ", "")).css({
                display: "block"
            });
        })
    })
        $(".state > div > ul > li").each(function(){
        $(this).hover(function(){
            $(this).children("ul:hidden").children("li:first-child").css("background-color", "transparent");
            
            if ($(this).find("div").html() == null) {
                $(this).children("ul").children("li").eq($(this).children("ul").children("li").size() - 1).after("<div id='png' class='menubottom'></div>");
            }
            $(this).find("ul:hidden").eq(0).css({
                "display": "block", "z-index": "999"
            });
        }, function(){
            $(this).find("ul").css({
                display: "none"
            });
        })
    })
	
	 $(".state > div > ul > li > ul > li").each(function(){
        $(this).hover(function(){
            
            if ($(this).find("div").html() == null) {
                $(this).children("ul").children("li").eq($(this).children("ul").children("li").size() - 1).after("<div id='png' class='menubottom'></div>");
            }
            
            $(this).find("ul:hidden").eq(0).css({
                "display": "block", "z-index": "999"
            });
        }, function(){
            $(this).find("ul").css({
                display: "none"
            });
        })
    })
    $("#movepage").css({
        width: $("#movepage dl").size() * 220 + "px"
    });
    setInt();
    
    $("a").each(function(){
        if ($(this).attr('target') == "_blank") {
            var a = $(this).attr("href");
            $(this).click(function(){
                window.open(a, 'newwindow', 'height=700, width=700, top=0, left=0, toolbar=yes,menubar=yes,scrollbars=yes,  resizable=yes,location=yes, status=yes');
            });
            $(this).removeAttr("href");
            $(this).css('cursor', 'pointer')
        }
    })
})

function setInt(){
    titleIndex = 0;
    titleNum = $("#title p").size();
    setInterval('changeTitle()', 5000);
}

function changeTitle(){
    $("#title p").eq(titleIndex).fadeOut(300, function(){
        $("#title p").eq((titleIndex + 1) % titleNum).fadeIn(300)
    })
    setTimeout('titleIndex = (titleIndex+1)%titleNum', 500);
}

function rightmove(){
    if ($("#staticpage").scrollLeft() < 220 * ($("#movepage dl").size() - 3)) 
        $("#staticpage").animate({
            scrollLeft: '+=220px'
        }, "slow");
}

function leftmove(){
    $("#staticpage").animate({
        scrollLeft: '-=220px'
    }, "slow");
}

