/**
 * Created by JetBrains WebStorm.
 * User: KAKA
 * Date: 10/23/11
 * Time: 2:30 PM
 * To change this template use File | Settings | File Templates.
 */

function tnhome() {
	var $slide = $(".tnhome");
	var index = 0;
	var dur = 10000;
	var itvobj;

	bindData();
	itvobj = setInterval(bindData, dur);
	
    $(".tnhome .newso li").hover(function () {
		clearInterval(itvobj);
        index = $(this).index();
		bindData();
    }, function() {
		itvobj = setInterval(bindData, dur);
	});
	
	$(".tnhome .news").hover(function() {
		clearInterval(itvobj);
	}, function() {
		itvobj = setInterval(bindData, dur);
	});	
	
	function bindData() {		
		$slide.find(".newso .ptw img").css("zIndex", 0);
		$slide.find(".newso .ptw").eq(index).children("img").css("zIndex", 1);
		
		//bind data
		$slide.find(".imgnews").attr("src", arItemSlide[index][8]);
		$slide.find(".titlenews").text(arItemSlide[index][1]);
		$slide.find(".titlenews").attr('href', (arItemSlide[index][2]));
		$slide.find(".leadnews").text(arItemSlide[index][4]);
		$slide.find(".ptw").attr("href", arItemSlide[index][2]);
		
		var $sts = $slide.find(".sts");
		$sts.html("");
		//alert(arItemSlide[index][9]);
		if(arItemSlide[index][9] == 1)
			$sts.append('<img class="ico-photo" src="Images/bg/blankk.gif" alt="">');
		if(arItemSlide[index][10] == 1)
			$sts.append('<img class="ico-video" src="Images/bg/blankk.gif" alt="">');		
		
		if(index < 3)
			index++;
		else 
			index = 0;
	}
}

function navtop() {
	var badBrowser = (/MSIE ((5\.5)|6|7|8)/.test(navigator.userAgent) && navigator.platform == "Win32");		
	var $duration = 400;
	var flagDeActive = false;
	$('#gocdocgia, #thugian, #phongcach, #thoicuoc, #thethao, #hautruong').mouseenter(function(){
		$(".activeMn").removeClass("activeMn");	
		$(this).find("a:first-child").addClass("menuhover");
		$(this).find('.dropMenu').addClass("activeMn");
		$(".activeMn").find(".dropUp").children().hide();
		$(".activeMn").show();
		$("#loadsubmenu").show().delay($duration).queue(function(){
			$("#loadsubmenu").hide();
			$(".activeMn").find(".dropUp").children().fadeIn($duration);										 
			$(this).dequeue();
		});
	});
	
	$('#gocdocgia, #thugian, #phongcach, #thoicuoc, #thethao, #hautruong').mouseleave(function(){
		$("#loadsubmenu").hide();
		$(this).find("a:first-child").removeClass("menuhover");
		if (badBrowser) 
			$(".dropMenu").hide();
		else 
			$(".dropMenu").fadeOut($duration);
	});
}

function acchor() {

    var cr = 0;
    var tt = $(".newscr li").length;
    var dur = 500; //effect
    var durmv = 10000; //move
    var ismove = false;
    var itvAcchor;

    itvAcchor = setInterval(autoAcchor, durmv);

    $(".newscr, .prevacchor, .nextacchor").bind("mouseenter", function() {
        clearInterval(itvAcchor);
    });

    $(".newscr, .prevacchor, .nextacchor").bind("mouseout", function() {
        clearInterval(itvAcchor);
        itvAcchor = setInterval(autoAcchor, durmv);
    });

    $(".prevacchor").bind("click", function() {
        if(cr < (tt - 1) && !ismove) {
            cr++;
            moveAcchor($(".newscr li:eq(" + (cr) + ") .head a"));
        }
    });

    $(".nextacchor").bind("click", function() {
        if(cr > 0 && !ismove) {
            cr--;						
            moveAcchor($(".newscr li:eq(" + (cr) + ") .head a"));
        }
    });

    $(".newscr .head a").bind("click", function() {
        if(!ismove) {
            cr = $(this).parents("li").index();
            moveAcchor($(this));
        }
        return false;
    });

    function autoAcchor() {
        if(!ismove) {
            if(cr == (tt - 1))
                cr = 0;
            else
                cr++;
            moveAcchor($(".newscr li:eq(" + (cr) + ") .head a"));
        }
    }

    function moveAcchor(obj) {
        var $this = obj;

        ismove = true;

        $this.parents("li").animate({
            left: eval($this.parents("li").index())*35,
            opacity: 1
        }, dur);

        //huong di chuyen
        if($this.parents("li").index() > $(".newscr .active").index()) {
            //$("#kk").text("1");
            $(".newscr li").each(function(index) {
                if(index < $this.parents("li").index()) {
                    $(this).animate({
                        left: index*35
                    }, dur);
                }
            });
        } else {
            //$("#kk").html("2");
            $(".newscr li").each(function(index) {
                if(index > $this.parents("li").index()) {
                    $(this).animate({
                        left: (index-1)*35 + $this.parents("li").outerWidth()
                    }, dur)
                }
            });
        }

        $(".newscr .active .head").show().animate({
            opacity: 1
        }, dur);

        $(".newscr .active").removeClass("active");
        $this.parents("li").addClass("active");
        $(".lblc").attr({
            href: $this.attr("href"),
            title: $this.attr("title")
        }).text($this.attr("title"));

        $this.parent().animate({
            opacity: 0
        },dur, function() {
            ismove = false;
        }).hide();

        $this.parents("li").children("a, h3, p").css("opacity", "0").animate({
            opacity: 1
        }, 1200);
    }

}



