// Mediagallery module
//function updateMediaContainer(file_fullname, width, height, autostart, show_description, item_id, gallery, gallery_files, playlist){
//	$('#imageContainer').html('<div class="loader"><img src="/javascript/ajax-loader_black.gif"></div>');
//	$('#mediaDescription').slideUp(100);
//	$.ajax({
//		type:"post",
//		url:"/mediapresentator/updateMediacontainer.php",
//		data: { updateMediaContainer: 1, 
//				file_fullname: file_fullname, 
//				width: width, 
//				height: height, 
//				autostart: autostart, 
//				show_description: show_description, 
//				item_id: item_id,
//				gallery: gallery,
//				gallery_files: gallery_files,
//				playlist: playlist
//		},
//		dataType: "json",
//		success:function(data) {
//			if (data == null){
//				updateMediaContainer(file_fullname, width, height, autostart, show_description, item_id, gallery, gallery_files, playlist);
//			} else {				
//				$('#mediaContainer').html(data.content);
//				$('#mediaContainer #imageContainer img').hide().fadeIn(200);
//				$('#mediaDescription').hide().slideDown(200);
//			}
//		}
//	});
//}

function updateMediaContainer(file_fullname, width, height, autostart, show_description, item_id, gallery, gallery_files, playlist){
	var $timeout_counter = 0;
	$.ajax({
		type:"post",
		url:"/mediapresentator/updateMediacontainer.php",
		data: { updateMediaContainer: 1, 
				file_fullname: file_fullname, 
				width: width, 
				height: height, 
				autostart: autostart, 
				show_description: show_description, 
				item_id: item_id,
				gallery: gallery,
				gallery_files: gallery_files,
				playlist: playlist
		},
		dataType: "json",
		timeout: 20000,
		beforeSend: function(){
			$('#mediaDescription').slideUp(100);
			$('#imageContainer').html('<div class="loader"><img src="/javascript/ajax-loader_black.gif"></div>');
		},
		success:function(data, textStatus, jqXHR) {
//			if (data == null){
//				$timeout_counter++;
//				updateMediaContainer(file_fullname, width, height, autostart, show_description, item_id, gallery, gallery_files, playlist);
//			} else {
				$('#mediaContainer').html(data.content);	
//			}
		},
		error: function(jqXHR, textStatus, errorThrown){
			$('#imageContainer').html('<div class="error_status">Error: '+textStatus+'</div>');
		},
		complete: function(){
			$('#mediaContainer #imageContainer img').hide().fadeIn(200);
			$('#mediaDescription').hide().slideDown(200);
		}
	});
}

// Mediapage
function updateMediaContainer2(file_fullname, width, height, autostart, show_description, item_id){
	$('#imageContainer').html('<div class="loader"><img src="/javascript/ajax-loader_black.gif"></div>');
	$('#mediaDescription').slideUp(100);
	$.ajax({
		type:"post",
		url:"/mediapresentator/updateMediacontainer.php",
		data: { updateMediaContainer2: 1, 
				file_fullname: file_fullname, 
				width: width, 
				height: height, 
				autostart: autostart, 
				show_description: show_description, 
				item_id: item_id
		},
		dataType: "json",
		success:function(data) {
			if (data == null){
				updateMediaContainer2(file_fullname, width, height, autostart, show_description, item_id);
			} else {
				$('#mediaContainer').html(data.content);
				$('#mediaContainer #imageContainer img').hide().fadeIn(200);
				$('#mediaDescription').hide().slideDown(200);
			}
		}
	});
}

// Client login mediaplayer
function updateMediaContainer3(file_fullname, width, height, item_id, gallery, gallery_files, current_folder){
	$('#imageContainer').html('<div class="loader"><img src="/javascript/ajax-loader_black.gif"></div>');
	$('#mediaDescription').slideUp(100);
	$.ajax({
		type:"post",
		url:"/mediapresentator/updateMediacontainer.clientlogin.php",
		data: { updateMediaContainer3: 1, 
				file_fullname: file_fullname, 
				width: width, 
				height: height, 
				item_id: item_id,
				gallery: gallery,
				gallery_files: gallery_files,
				current_folder: current_folder
		},
		dataType: "json",
		success:function(data) {
			if (data == null){
				updateMediaContainer3(file_fullname, width, height, item_id, gallery, gallery_files, current_folder);
			} else {
				$('#mediaContainer').html(data.content);
				$('#mediaContainer #imageContainer img').hide().fadeIn(200);
				$('#mediaDescription').hide().slideDown(200);
			}
		}
	});
}


$(document).ready(function() {
	$('#mediaPlaylist a').live('click', function(event){
		event.preventDefault();
	});
	
//$(".nyroModal").nyroModal(
//		{
//			bgColor: '#ffffff',
//			width: 1920,
//			height: 500
//		}
//	);
//	$.nyroModalSettings({
//    processHandler: function(settings) {
//      var from = settings.from;
//      if (from && from.href && from.href.indexOf('http://www.youtube.com/watch?v=') == 0) {
//        $.nyroModalSettings({
//          type: 'swf',
//          height: 355,
//          width: 425,
//          url: from.href.replace(new RegExp("watch\\?v=", "i"), 'v/')
//        });
//      }
//    }
//  });

});

$(window).load(function(){
												
/*	$(".nyroModal").live('click', function(e){
			e.preventDefault();
			$(this).nyroModalManual();
			//$.nmTop()._callFilters('galleryNext');
	});*/
	
//	$(".nyroModalNext").live('click', function(e){
//			//e.preventDefault();
//			alert('yes yes');
//	});
	
	$('#slider').nivoSlider({
		effect:'fade', //Specify sets like: 'fold,fade,sliceDown'
		slices:1,
		animSpeed:800, //Slide transition speed
		pauseTime:4200,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:false, //Next & Prev
		directionNavHide:true, //Only show on hover
		controlNav:false, //1,2,3...
		controlNavThumbs:false, //Use thumbnails for Control Nav
    	controlNavThumbsFromRel:false, //Use image rel for thumbs
		controlNavThumbsSearch: '.jpg', //Replace this with...
		controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
		keyboardNav:true, //Use left & right arrows
		pauseOnHover:true, //Stop animation while hovering
		manualAdvance:false, //Force manual transitions
		captionOpacity:0.8, //Universal caption opacity
		beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){} //Triggers after all slides have been shown
	});
	
	/* PLAY LIST */
	//$('#mediaPlaylist').fadeIn(200);
	
	
	
//	$('#mediaPlaylist a.item').click(function() {
//		$('#mediaPlaylist a.active').removeClass('active');
//		$(this).addClass('active');
//	});
//	$('a.item').live('mouseover', function(event) {
//		$('a.item').qtip({ style: { name: 'dark', tip: true } });
//  });
	
	/* PLAY LIST NEXT ITEM */
	
	$('#mediaPlaylist .next').live('click', function(){
		var current = $('#mediaPlaylist a.active');
		var next = current.next('a.item');
		if (next.length != 0){
			//current.removeClass('active');
			next.click();
			//next.addClass('active');
			//alert(next.attr('onClick'));
			
		}
	});
	
	/* PLAY LIST PREVIOUS ITEM */
	$('#mediaPlaylist .prev').live('click', function(){
		//$('#mediaPlaylist a.active').removeClass('active');
		var current = $('#mediaPlaylist a.active');
		var previous = current.prev('a.item');
		if (previous.length != 0){
			//current.removeClass('active');
			previous.click();
			//previous.addClass('active');
		}
	});																							 
	
});

/*$(document).ready(function() {
	$('#mediaPlaylist').hide().fadeIn(200);							 
});*/

