//var lastBlock = jQuery("#a1");
var lastBlock = jQuery("#image_nav_main ul li.last a");
var maxWidth = 351;
var minWidth = 172;
var is_ie6 = false;

// ie6
if(jQuery.browser['msie'] && jQuery.browser['version']=='6.0'){
	var is_ie6 = true;
}

var hoverTO = '';

function hoverMe(element)
{
    jQuery(lastBlock).attr('class','gone').animate(
    {
		//width: ((jQuery(element).parent().hasClass('last'))? ((is_ie6)? minWidth+10:minWidth) : minWidth)+"px"
		width: ((is_ie6)? ((jQuery(lastBlock).parent().hasClass('last'))? minWidth-10:minWidth):minWidth)+"px"
		//width: minWidth+"px"
	},
    {
		queue:false,
		duration:400
	});
    jQuery(element).attr('class','active').animate(
    {
		//width: ((jQuery(element).parent().hasClass('last'))? ((is_ie6)? maxWidth:maxWidth) : maxWidth)+"px"
		width: ((is_ie6)? maxWidth:maxWidth)+"px"
		//width: maxWidth+"px"
	},
    {
		queue:false,
		duration:400
	});
    lastBlock = element;
}

function swapNext()
{
    window.clearInterval(hoverTO);
    var next= false;
    var hovered = false;
    //foreach current find the current and hover the next
    jQuery("#image_nav_main ul li a").each(function(index)
	{
		if(jQuery(this).attr('id')=='')
		{
	        if(jQuery(this).hasClass('active'))
			{
	            next = true;
	        }
	        else if(next)
			{
	            hoverMe(this);
	            hovered = true;
	            next = false;
	            return;
	        }
		}
    });
    if (!hovered)
	{
        //was the last - so activate first
        hoverMe(jQuery("#image_nav_main ul li :first"));
    }
    hoverTO = window.setInterval('swapNext()',7000);
}

// set to noConflict Mode cause of swfobject
jQuery.noConflict();


jQuery(document).ready(function()
{
	jQuery('#image_nav_main ul > a').remove();
	jQuery('#image_nav_main li a').each(function()
	{
		if(jQuery(this).attr('id')!='')
		{
			jQuery(this).remove();
		}
	});

	if(jQuery("#videoplayer").length>0)
	{
		if(jQuery.trim(jQuery("#videoplayer").html())=='')
		{
			jQuery("#videoplayer").remove();
			jQuery("#col1_content .content_item").css({'border':'0px'});
		}
	}
	else if(jQuery("#col1_content").length>0)
	{
		if(jQuery.trim(jQuery("#col1_content .content_item").html())=='')
		{
			jQuery("#col1_content .content_item").css({'border':'0px'});
		}
	}
	
    jQuery("#image_nav_main ul li a").hover(function()
	{
        window.clearInterval(hoverTO);
		hoverMe(this);
    },
    function()
	{
		hoverTO = window.setInterval('swapNext()',3000);
    });
    hoverTO = window.setInterval('swapNext()',0);
});
