
var timer = 3;
var currentNode = 0;
var homeTimer = null;

function fnShiftHomeSlidePanel(node){
	currentNode = node;

    var parent_ul = jq(node).closest('.home_flash_outter .home_flash_inner ul.home_slide');
    parent_ul.children('li').children('div.home_slide_content').each(function(){
        jq(this).fadeOut('slow');
    });
    parent_ul.children('li').children('p.home_slide_tab').children('a').each(function(){
        jq(this).removeClass("selected");
    });
    jq(node).addClass("selected");
    jq(node).closest('p.home_slide_tab').next("div.home_slide_content").fadeIn('slow');
}
            


jq(document).ready(function(){
    var container_node = jq('.home_flash_outter .home_flash_inner');
    var h1_list = jq('.home_flash_outter .home_flash_inner > h1');
    var h2_list = jq('.home_flash_outter .home_flash_inner > h2');
    var link_list = jq('.home_flash_outter .home_flash_inner > p > a');
    var image_list = jq('.home_flash_outter .home_flash_inner > p > img');
    
    var aryHtml = [];
    for(var i = 0; i < h1_list.size(); i++){
        aryHtml.push('<li><p class="home_slide_tab"><a href="#"><span>' + jq(h1_list[i]).text() + '</span></a></p><div class="home_slide_content" style="background-image: url(' + image_list[i].src + ')"><h1>' + jq(h1_list[i]).html() + '</h1><h2>' + jq(h2_list[i]).html() + '</h2><p class="home_slide_view_more"><a href="' + link_list[i].href + '"><span>' + jq(link_list[i]).text() + '</span></a></p></div></li>');
    }
    container_node.empty();
    container_node.append('<ul class="home_slide">' + aryHtml.join('') + '</ul>');
    
    jq('.home_flash_outter').css({'background-image' : 'none'});
    container_node.show();
    
    jq('.home_flash_outter .home_flash_inner ul.home_slide > li > p.home_slide_tab a').each(function(){
        jq(this).bind('click', function(){
			clearTimeout( homeTimer );

			

            fnShiftHomeSlidePanel(this);
            return false;
        });
    });
    
    jq('.home_flash_outter .home_flash_inner ul.home_slide > li > div.home_slide_content').each(function(){
        jq(this).hide();
    });
    jq('.home_flash_outter .home_flash_inner ul.home_slide > li:first-child > div.home_slide_content').show();
    jq('.home_flash_outter .home_flash_inner ul.home_slide > li:first-child > p.home_slide_tab a').addClass("selected");


    currentNode = jq('.home_flash_outter .home_flash_inner ul.home_slide > li:first-child > p.home_slide_tab a');
	homeTimer = setTimeout(function(){autoRot();}, timer * 1000);
    jq('.home_flash_outter .home_flash_inner ul.home_slide').hover(
        function(){
            clearTimeout( homeTimer );
        },
        function(){
            homeTimer = setTimeout(function(){autoRot();}, timer * 1000);
        }
    );
/*
	jq('.products_dropdown').each(function(){
		var css_class = jq(this).attr('id').replace('_','-');
		var navItem = jq(this);

		jq('#nav li.' + css_class).hover(
		  function () {
			jq('#nav li.' + css_class + ' a', this).addClass('slide-down');
			//jq(navItem, this).slideDown(100,'easeInQuad');
			jq(navItem, this).slideDown(200);
		  },
		  function () {
			obj = this;
			jq(navItem, this).slideUp(200, function(){
				jq('#nav li.' + css_class + ' a', obj).removeClass('slide-down'); 
			});
		  }
		);

		jq(this).slideUp(0);
	});
*/


});

function autoRot(){
    var nextNode = jq(currentNode).closest('li').next('li').children('p.home_slide_tab').children('a');

	if(!nextNode.html()){
		nextNode = 	jq('.home_flash_outter .home_flash_inner ul.home_slide > li:first-child > p.home_slide_tab a');
	}
	homeTimer = setTimeout(function(){autoRot();}, timer * 1000);
	fnShiftHomeSlidePanel( nextNode );
}
