/*$(document).ready(function() {

	$(".fancybox").fancybox();
	
	
	$("a#inline").fancybox({
		'hideOnContentClick': true
	});

	
	$("a.group").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false
	});
	
});
*/
// ajax and jquery.address
$.address.init(function(event) {

	 // Initializes plugin support for links
	 $('a:not([href^=http])').not('.noAjax').address();

}).change(function(event) {

	 // Identifies the page selection 
	 var page = event.parameters.page ? '/?page=' + event.parameters.page : event.path;


	var pathArray = window.location.pathname.split('/');
	var currentDirectory = pathArray[1];
	
	//console.log(currentDirectory != "index.php" && currentDirectory != "" );
//	console.log(event.path == "/");
	
	if (currentDirectory != "index.php" && currentDirectory != "" )
	{
		if (event.path == "/")
		{
			var contentUrl = "/content/" + currentDirectory + "/index.php";
		}
		else
		{
			var contentUrl = event.path;
		}
		
		//console.log("contentUrl: " + contentUrl);
		
		$.ajax({
			url: contentUrl,
			cache: false,
			success: function(html){
				
				//console.log('--' + event.path);
				
				// select active menu item if present
				if (event.path == "/")
				{
					 $('.menu-subnav ul').children().first().addClass('active');
				}
				else
				{
					$('.menu-subnav li').each(function(index){
						//console.log($(this).children().first().attr('rel'));
						if( 'address:' + contentUrl === $(this).children().first().attr('rel') ) {
							$(this).addClass('active');
							//s += index + ': true \n';
						} else {
							$(this).removeClass('active');
							//s += index + ': false \n';			
						}
					});
				}
				
				$("#ajaxContent").empty();
				$("#ajaxContent").append(html);
				$("#ajaxContent").children().hide();
				$('#ajaxContent').children().fadeIn();								
				//bindAjaxLinks();
				
				 $('a.toTop').click(function(){
					  $('html, body').animate({scrollTop:0});
					  return false;
				 });

				// set active main menu
				$('.menu-main li').each(function(index){
					//console.log(currentDirectory + " :: " + $(this).children().first().attr('href').split('/')[1]);
					
					if(currentDirectory == $(this).children().first().attr('href').split('/')[1])
					{
						$(this).addClass('active');
						//s += index + ': true \n';
					} else {
						$(this).removeClass('active');
						//s += index + ': false \n';			
					}
				});
				
				// initialize other pluggins
				$(".fancybox").fancybox();
				
					// fancybox youtube
				$("a.youtube").click(function() {
					$.fancybox({
						'padding'       : 0, //optional
						'title': this.title,
						'width': 800, //or whatever
						'height': 530, //or whatever
						'href': this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
						'type': 'swf',
						'swf': {
						'wmode': 'opaque',
						'allowfullscreen'       : 'true'
						}
					});
					return false;
				});
				
				// jquery tabs
				$( ".jquery-tabs" ).tabs();
				$( ".jquery-tabs-mouseover" ).tabs({
						/*event: "mouseover"*/
					});
				
				$('.ui-tabs-panel').addClass('ui-corner-top');
				
			},
			error: function(jqXHR, textStatus, errorThrown)
			{
				alert("Ajax Error: " + jqXHR.responseText);
			}
		});

	}


});



