jQuery(document).ready(function($) {


	// INITIALIZE GALLERY SUPPORT
	/*$(".gallery a").prettyPhoto({
		opacity: 0.75, 
		theme: 'dark_rounded', 
		allowresize: false,  
	});*/
	
	//$(".gallery a").live('click', function() {
		$(".gallery a").attr('rel', 'gallery');
	//});
	
	$("a[rel^='gallery']").prettyPhoto({
				animationSpeed: 'normal', 
				opacity: 0.75, 
				showTitle: false, 
				allowresize: true, 
				counter_separator_label: '/', 
				theme: 'dark_rounded', 
				hideflash: false, 
				modal: false, 
				changepicturecallback: function(){}, 
				callback: function(){} 
			});
	
	/*$(".gallery a").click(function() {
		alert('ahh');
	});*/
	
	// DROPDOWN MENU
	
	$('#menu li').children('ul').animate({ 'opacity':'0.1' }, 1) //Initialize opacity
	$('#menu li').hover(
	
		//Hover
		function() {
			//alert('yeah!');
			//$(this).children('ul').animate({ 'top': ''});
			$(this).children('ul').slideDown(200);
			/*ulw = $(this).children('ul').css('width');
			$(this).animate({ 'top': '-=' + ulw + 'px' });*/
			$(this).children('ul').animate({ 'opacity':'1' }, 200);
		}, 
		
		//Out
		function() {
			$(this).children('ul').slideUp(200);
			$(this).children('ul').animate({ 'opacity':'0.1' }, 200);
		}
		
	);
	
	//LINK HOVER
	
	/*$('a').tooltip({
		fixPNG: true, 
		showURL: true
		, 
	});*/
	
	var showtooltips = $('#theme_showtooltips').attr('value');
	if(showtooltips == 1) {
		$("a[title]").tooltip({
			tip: '#demotip', 
			effect: 'fade', 
			opacity: 0.7, 
			position: 'top right'
		});
	}
	
	//HOT NEWS SLIDER
	
	HNspeed = $('#theme_hnspeed').attr('value') * 1000;
	
	HNcurrent = 1;
	HNtimeron = 1;
	HNmoving = 0;
	
	HNcount = $('#hotlinks a').size();
	
	//motion = 0;
	
	function HNMoveForward() {
	
		HNmoving = 1;
		
		if(jQuery.support.opacity) {

			$('#hotlinks').fadeTo(HNspeed/10, 0.33, function() {
				$('#hotlinks span').animate({ 'top' : '-=16px' }, HNspeed/10, function() {
					HNcurrent++;
					$('#hotlinks').fadeTo(HNspeed/8, 1, function() {
						HNmoving = 0;
					});
				});
			});
		
		}
		else {

			$('#hotlinks span').animate({ 'top' : '-=16px' }, HNspeed/10, function() {
				HNcurrent++;
				HNmoving = 0;
			});
		
		}
		
	}
	
	function HNMoveToItem(item) {
	
		HNmoving = 1;
		
		if(jQuery.support.opacity) {

			$('#hotlinks').fadeTo(HNspeed/19, 0.33, function() {
				target = (16 * item) - 16;
				$('#hotlinks span').animate({ 'top' : target + 'px' }, HNspeed/10, function() {
					HNcurrent = item;
					$('#hotlinks').fadeTo(HNspeed/10, 1, function() {
						HNmoving = 0;
					});
				});
			});
		
		}
		else {

			$('#hotlinks span').animate({ 'top' : target + 'px' }, HNspeed/10, function() {
				HNcurrent = item;
				HNmoving = 0;
			});
		
		}
		
	}
	
	HNslider = window.setInterval(function () {
		
		if(HNtimeron == 0) { clearInterval(HNslider) }
		
		if(HNcurrent < HNcount && HNtimeron == 1) {
			HNMoveForward();
		}
		
		if(HNcurrent == HNcount && HNtimeron == 1) {
			HNMoveToItem(1);
		}
		
	}, HNspeed);
	

});