$(document).ready(function(){
	var startnum = 0;
	function reloadTitle(bigtitle, smalltitle, nowindex){
				$('.is-description h1').fadeOut(500);
				$('.is-description p').fadeOut(500);
				$('.is-description h1').queue(function(){
					$(this).text(bigtitle);
					$(this).dequeue();
				});
				$('.is-description h1').fadeIn(500);
				$('.is-description p').queue(function(){
					$(this).text(smalltitle);
					$(this).dequeue();
				});
				$('.is-description p').fadeIn(500);
				startnum = nowindex;	
	}
	function checkimage(){
			$('.is-navigation a').each(function(index){
				var kelas = $(this).attr('class');
				if(kelas=='activeSlide'){
					var now = index
					$('.image-slideshow-list img').each(function(index){
						if(now==index&&now!=startnum)
						{
							var bigtitle = $(this).attr('alt');
							var smalltitle = $(this).attr('title');
							reloadTitle(bigtitle, smalltitle, now);
						}
					});
				}
		});
		
	}
	
	var refreshInterval = window.setInterval(checkimage, 500);	

	if(page=="home"  || page=="splash")
		refreshInterval;
	var page = $('body').attr('id');
	var browser = navigator.appName;
	
	if (navigator.userAgent.indexOf('Firefox') !=-1)
		{
			//do something here
		}
		
	$("#tree-dropdown").treeview({
		toggle: function() {
			console.log("%s was toggled.", $(this).find(">span").text());
		}
	});
	
	$('.image-slideshow-list').cycle({
		fx:     'fade', 
		speed:  'slow', 
		timeout: 10000, 
		pager:  '.is-navigation' 			
	});	
	
	$('.is-navigation a').live('click', function(){
		var linkindex = $('.is-navigation a').index(this);
		$('.image-slideshow-list img').each(function(index){
			if(linkindex==index){
				var bigtitle = $(this).attr('alt');
				var smalltitle = $(this).attr('title');
				reloadTitle(bigtitle, smalltitle, linkindex);
			}
		});
	});
	
	$(".home-featured").cycle({
		fx:     'fade', 
		speed:  'slow', 
		timeout: 0, 
		pager:  '.is-navigation' 				
	});
	
	$('a.ht-events').click(function(event){
			event.preventDefault();
			$(this).attr('class','ht-events-selected');
			$('a.ht-news').attr('id','ht-notselected');
			$('a.ht-news-selected').attr('class','ht-news');
			$('a.ht-press-selected').attr('class','ht-press');
			$('#ht-news-content').css('display','none');
			$('#ht-event-content').css('display','block');
			$('#ht-press-content').css('display','none');
	});

	$('a.ht-news').click(function(event){
			event.preventDefault();
			$(this).attr('class','ht-news-selected');
			$('a.ht-events-selected').attr('class','ht-events');
			$('a.ht-press-selected').attr('class','ht-press');
			$('#ht-news-content').css('display','block');
			$('#ht-event-content').css('display','none');
			$('#ht-press-content').css('display','none');
	});

	$('a.ht-press').click(function(event){
			event.preventDefault();
			$(this).attr('class','ht-press-selected');
			$('a.ht-news').attr('id','ht-notselected');
			$('a.ht-events-selected').attr('class','ht-events');
			$('a.ht-news-selected').attr('class','ht-news');
			$('#ht-news-content').css('display','none');
			$('#ht-event-content').css('display','none');
			$('#ht-press-content').css('display','block');
	});
	
	if(page=="home"  || page=="splash")
	{
		var slider = 0;
		var number = 0;
		$('.hp-content img').each(function(index){
			number = index;
		});
		
		if(slider==0)
		{
			$('a.prev-promo').css('background-position','left');
		}

		$('a.prev-promo').click(function(event){
			event.preventDefault();
			if(slider!=0){
				slider=slider-1;
				$('a.next-promo').css('background-position','left');
				$('.hp-content img').each(function(index){
					$(this).attr('class','slide-none');
					if(slider==index)
					{
						$(this).attr('class','slide-display');
					}
				});
				if(slider==0)
				{
					$('a.prev-promo').css('background-position','left');						
				}
			}
		});

		$('a.next-promo').click(function(event){
			event.preventDefault();
			if(slider!=number){
				slider=slider+1;
				$('a.prev-promo').css('background-position','right');
				$('.hp-content img').each(function(index){
					$(this).attr('class','slide-none');
					if(slider==index)
					{
						$(this).attr('class','slide-display');
					}
				});
				if(slider==number)
				{
					$('a.next-promo').css('background-position','right');						
				}
			}
		});

	}
	
});

