// JavaScript Document
$(document).ready(function () {
	//NAVIGATION HOVER
    $("#site_nav a").each(function () {
        if ($(this).siblings("ul").length != 0) {
            $(this).parent("li").addClass("hover");
        }
    });
    $("#site_nav li.hover").hover(function () {
        $(this).children("ul").stop(true, true).slideDown();
    }, function () {
        $(this).children("ul").stop(true, true).slideUp();
    });
	//TWITTER FEED ANIMATION (YOU NEED THE TIMER PLUGIN FOR THIS TO WORK SEE GLOBAL.JS)
    var tc = $("#tweets ul li").size(),
        th = $("#tweets ul").height(),
        tih = (th/tc),
        tr = 0,
        i = 1,
        timer = {};
		
    tweetAni();
    $("#tweets").hover(function () {
        $.clearTimer(timer);
    }, function () {
        tweetAni();
    });

    function tweetAni() {
        if (tc != 1) {
            timer = $.timer(5000, function () {
                $.clearTimer(timer);
                if (i == tc) {
                    $("#tweets ul").animate({
                        "top": tr + 'px'
                    },1000);
                    i = 1;
                } else {
                    $("#tweets ul").animate({
                        "top": '-' + (tih * i) + 'px'
                    },1000);
                    i++;
                }
                tweetAni();
            });
        }
    };
	//PRODUCT IMAGE ANIMATION
	$(".product_holder div").hide();
	$(".product_holder div:first").show();
	$(".thumb a").click(function(){
		var li = $(this).attr("class"),
			ci = $(".product_holder div:visible").attr("class");
		if(li != ci){
			$(".product_holder div").stop(true, true).fadeOut();
			$(".product_holder ."+li).stop(true, true).fadeIn();
		}
		return false;
	});
	//PAGE SIDEBAR ACCORDIAN
	$(".sidebar_page ul.children").hide();
	$(".current_page_parent ul.children").show();
	$(".sidebar_page ul li").children("a").click(function(){
		if($(this).siblings("ul.children").length == 1){
			if($(this).siblings("ul.children").is(":visible")){
				$(this).siblings("ul.children").slideUp();
			} else {
				$("ul.children").slideUp();
				$(this).siblings("ul.children").slideDown();
			}
			return false;
		}
	});
});
