// POST JSON


$(document).ready(function(){


$('.topsearch').click(
function() {
	if (this.value == this.defaultValue) {
		this.value = '';
	}
}
);
$('.topsearch').blur(
function() {
	if (this.value == '') {
		this.value = this.defaultValue;
	}
}
);

	$('#slider').before('<div id="nav">').cycle({ 
			fx:     'fade',
			speed:   2000, 
			timeout: 7000, 
			pager:  '#nav' 
	});

// FLASHEMBED
	//flashembed("flash", { src: "/flashes/index.swf", wmode: 'opaque', version: [9, 0], expressInstall: "/flashes/expressinstall.swf" });
	
// ROTATION
	function changeNews() {
		var s = $("div[id^='newsrotate']").length;
		var p = 1, i = 1;
		
		$("div[id^='newsrotate']").each(function(){
			if ($(this).is(':visible')) p = i;
			i += 1;
		});
		if (p>=s) var n = 1;
		else var n = p+1;
		$('#newsrotate'+p).fadeOut("slow",function(){
			$('#newsrotate'+n).fadeIn("slow",function(){
				setTimeout(changeNews,7000);
			});
		});
	}

	function changeQuotes() {
		var s = $("div[id^='quotesrotate']").length;
		var p = 1, i = 1;
		
		$("div[id^='quotesrotate']").each(function(){
			if ($(this).is(':visible')) p = i;
			i += 1;
		});
		if (p>=s) var n = 1;
		else var n = p+1;
		$('#quotesrotate'+p).fadeOut("slow",function(){
			$('#quotesrotate'+n).fadeIn("slow",function(){
				setTimeout(changeQuotes,7000);
			});
		});
	}

	function changeVideos() {
		var s = $("div[id^='videosrotate']").length;
		var p = 1, i = 1;
		
		$("div[id^='videosrotate']").each(function(){
			if ($(this).is(':visible')) p = i;
			i += 1;
		});
		if (p>=s) var n = 1;
		else var n = p+1;
		$('#videosrotate'+p).fadeOut("slow",function(){
			$('#videosrotate'+n).fadeIn("slow",function(){
				setTimeout(changeVideos,7000);
			});
		});
	}


	setTimeout(changeNews,8000);
	setTimeout(changeQuotes,7000);
	setTimeout(changeVideos,9000);
	
// SCROLLABLE
//	$("#infinite").scrollable().circular().autoscroll({autoplay: true, autopause: true, interval: 5000, clickable: true});

// NAVIGATION
	$("#topnav ul").superfish(); 
	
});
