var intval = null;

function nextSlide() {
    var active = $('#splash-control li.active');
    if ( active.length == 0 ) var active = $('#splash-control li:last');
    var next = active.next().length ? active.next() : $('#splash-control li:first');
    active.removeClass();
    next.addClass('active');
    $('#spash-image').html(
        $('#splash-content>'+next.children().attr('href')).html()
    );
}

function triggerSlideShow(){
	$('#widesplash').hide('slow');
	$('.widesplash-trigger').remove();
	intval = setInterval( 'nextSlide()', 5000 );
}

$(document).ready(function(){

	var fslide = $('#spash-image').html();
	$("#video-panel img, #overlay-trigger").click(function() { 
	    flowplayer('player', { 
	        src: '/js/flowplayer/flowplayer-3.1.2.swf',          
	        onFail: function()  { 
	            document.getElementById("info").innerHTML = 
	                "You need the latest Flash version to view MP4 movies. " + 
	                "Your version is " + this.getVersion() 
	            ; 
	        }
	    }, { 
	        clip: '/videos/'+this.className+'.flv' 
	    });
		$(this).overlay({effect: 'apple'}); 
	});
	
//	setTimeout('triggerSlideShow()', 6000);
	var intval = setInterval( 'nextSlide()', 5000 );
	
	$('#newsticker').newsTicker();
	
	var pfh = $('#product-features').height();
	if(pfh>$('#product-description').height()) $('#product-description').height(pfh);
	
	$('#topMenu td img[class!=separate]').hover(
		function(){
			this.src = this.src.replace(/\.jpg/, '_a.jpg');
		},
		function(){
			this.src = this.src.replace(/_a\.jpg/, '.jpg');
		}
	);
	
	$('#splash-control a').click(function() {
//		$('#widesplash').remove();//@deprecated
//		$('.widesplash-trigger').remove();//@deprecated
		clearInterval(intval);
		$(this).parent().addClass('active').siblings().removeClass();
		$('#spash-image').html(
			$('#splash-content>'+$(this).attr('href')).html()
		);
	});
	
	$('#splash-title a').click(function() {
		clearInterval(intval);
		$('#spash-image').html(fslide);
		$('#splash-control li').removeClass();
	});
	
	$("div.scrollable").scrollable();
	
	$('img[rel]').overlay();
	
	$('.items div').click(function() {
		$('#products-wrapper>div').hide();
		$('#'+$(this).attr('title')).show();
	});
	
	var er = new Array();
	var count = 0;
	$('#fieldset-devid .errors, #fieldset-prepaid .errors').each(function(){
		var id = $(this).parent().parent().parent().attr('id');
		var val = $('>li',this).html();
		if(! er[id]) {
			er[id] = new Array();
			i=0;
			count++;
		}
		if($.inArray(val, er[id])==-1) {
			er[id][i] = $('>li',this).html();
			i++;
			if(i>1) {
				$(this).css('margin-top','-50px');
				if(count==1) $(this).css('margin-left','215px');
				if(count==2) $(this).css('margin-left','137px');
			}
		} else {
			$(this).remove();
		}
		
	});
	
	$("#poll-results div").each(function(){  
		$(this).css({width: "0%"}).animate({width: $(this).next().text()}, 'slow');
	});
});
	
	
