projects = {
	
	init : function() {
		$("#project-menu a").click(function() {
			$('#project .media-container').hide();
			$('#project-menu a').removeClass('active');
			projects.activate_group(this, $(this).attr('rel'));
			return false;
		});	
		
		// init everything else
		projects.activate_group($("#project-menu a:first"), '#photo');			

		if(!has_images) {
			$("#project-menu a.photo").unbind('click').addClass('innactive').removeAttr('href');
		}		
		if(!has_videos) {
			$("#project-menu a.video").unbind('click').addClass('innactive').removeAttr('href');
		}		
		if(!has_audios) {
			$("#project-menu a.audio").unbind('click').addClass('innactive').removeAttr('href');
		}
	},
	
	activate_group : function(e, group) {
		$(e).addClass('active');
		$(group).show();
		switch(group) {
			case "#photo":
				projects.init_gallery();
				break;
			case "#video":
				projects.init_videos();
				break;
			case "#audio":
				projects.init_audios();
				break;				
		};		
	},
	
	init_gallery : function() {		
		var count = $("#photos-slider img").length;
		if(jQuery.find("#images-numeric") == false) {
			$("#photos-slider").easySlider({
					auto: true,
					continuous: true,
					numeric: true,
					speed: 250,
					pause: 5000,
					controlsBefore: '<div class="pages"><span>Items:</span>',
					controlsAfter: '</div>',
					numericId: 'images-numeric',					
					stopOnClick: false
			});			
		}	
	},
	
	init_videos : function() {
		if(!$('#videos-slider').hasClass('init')) {
			$('a.video').each(function() {
				// params: "swf", "name", "300", "120", "9.0.0","expressInstall.swf", flashvars, params, attributes;
				$.swfobject.embedSWF('/swf/player.swf', this.id, "405", "257", "9.0.0", null, { 'file': this.href, 'skin': '/swf/skins/simple.swf' }, { allowscriptaccess: "always", allowfullscreen: "true" }, null);	
			});			
			slider.init('#videos-slider');
		}
	},
	
	init_audios : function() {
		if(!$('#audios-slider').hasClass('init')) {
			$('a.audio').each(function() {
				// params: "swf", "name", "300", "120", "9.0.0","expressInstall.swf", flashvars, params, attributes;
				$.swfobject.embedSWF('/swf/player.swf', this.id, "405", "20", "9.0.0", null, { 'file': this.href, 'skin': '/swf/skins/simple.swf' }, { allowscriptaccess: "always", allowfullscreen: "true" }, null);	
			});		
			slider.init('#audios-slider');
		}		
	}
	
};

slider = {
		
	init : function(el) {	
		var el = $(el);
		var maxWidth = $(el).width();
		var contentToScroll = $(el).find('ul');
		var count = $(el).find('ul li').length;	

		// flag true for init
		el.addClass('init');

		// init slidable content
		$(contentToScroll).css('width', maxWidth * count).css('position', 'absolute');
		
		// insert navigation
		var nav = this.insert_nav(el, count);
		
		// attach control to pager's links
		$(el).find('.pages a').click(function() {
			slider.activate_menu_item(nav, $(this).attr('rel'));
			slider.scroll_to($(this).attr('rel'), contentToScroll, maxWidth);
			slider.display_text($(this).attr('rel'), contentToScroll);
			
			// stop video/audio playback of any video player
			// slider.stop_playback();
			
			// prevent default			
			return false;
		});
		
		// display first item
		slider.activate_menu_item(nav, 0);
		slider.scroll_to(0, contentToScroll, maxWidth);
		slider.display_text(0, contentToScroll);			
	},
	
	// insert pager for each slider
	insert_nav : function (el, count) {
		div = $("<div/>").addClass('pages').appendTo(el);
		ol = $("<ol/>").addClass('numeric').appendTo(div);
		title = $("<span/>").text('Items:').appendTo(ol);
		for (var i=0; i < count; i++) {
			var n = i;
			var li = $('<li/>');
			var a = $('<a/>').attr('href', '#').attr('rel', i).text("0" + (i+1) + ".").appendTo(li);
			li.appendTo(ol);					
		};
		
		// return element for later manipulation
		return ol;		
	},
	
	scroll_to : function(n, contentToScroll, maxWidth) {
		n = parseInt(n);
		contentToScroll.animate({ left: n * maxWidth * -1 }, 250);		
	},
		
	display_text : function(n, contentToScroll) {
		// get main container
		el = contentToScroll.find('li').get(n);
				
		// find text
		var title = $(el).find('.item-title').html();
		var description = $(el).find('.item-description').html();		
		
		// find container
		var titleContainer = $(contentToScroll).parent().parent().find('h4.title');
		var descriptionContainer = $(contentToScroll).parent().parent().find('.description');
				
		// set text
		titleContainer.html(title);
		descriptionContainer.html(description);
	},
	
	activate_menu_item : function(nav, pos) {		
		pos = parseInt(pos);
		items = $(nav).find('li');
		$(items).each(function() { $(this).removeClass('current') });
		items[pos].className = 'current';
	},
	
	stop_playback : function() {
		// $('embed, object').each(function() {
		// 	var player = this;
		// 	console.log(player.getConfig());
		// 	// player.sendEvent("STOP","true");
		// });
		var player = document.getElementById('video_7');
		player.sendEvent("PLAY","true");
	}
 	
}  


// 
sub_menu = {
	
	init : function() {
		$.address.change(function(event) { 
			// do nothing if no path is found
			if(event.pathNames.length > 0) {
				sub_menu.show_section(event.pathNames[0]);	
			} 			
		});
	},   
	
	show_section : function(id) {
		  // hide everything and show current id
		$('.page-content, .section').hide();
		$('body').find('#' + id).show();
		                                      
		// active menu item
		$('ul.sections a').removeClass();
		$('a[href="#'+id+'"]').addClass('active');
	}
	
}