(function(){
	$(document).ready(function(){
		$('.startGallery').click(function(){
			$("a[rel='"+$(this).attr('id')+"']").colorbox({
				slideshow:true,
				open: true,
				next: 'neste',
				previous:	'forrige',
				maxHeight: $(window).height()+'px',
				scalePhotos:true,
				current: 'bilde {current} av {total}',
				slideshowSpeed: setTimeout($(this)),
				slideshowStart: 'Start fremvisning',
				slideshowStop: 'Stopp fremvisning'
				},function(){
					$().bind('cbox_closed',function(){
						document.getElementById("player").SetVariable("player:jsStop", "");
						$('.mp3Controls').css('visibility','hidden');
						});
				});
				var gId = $(this).attr('id').substr($(this).attr('id').length-1,1);
				
				function setTimeout(elem){
					var pic = $("a[rel='"+elem.attr('id')+"']");
					var timeout = pic.attr('class');
					timeout = timeout.substring(1)*1000;
					if(timeout<1000)
						timeout=2000;
					return timeout;
				}
				
				$('.mp3Controls').data('player',gId);
				if ($('#gallery'+gId+'mp3').length>0){
					
					document.getElementById("player").SetVariable("player:jsUrl", $('#gallery'+gId+'mp3').attr('href'));
					document.getElementById("player").SetVariable("player:jsPlay", "");
				}
				//if ($('#player'+gId).length>0)
				//	document.getElementById("player"+gId).SetVariable("player:jsPlay", "");
			
			//$('#'+$(this).attr('id')+'controls').css('visibility','visible');'
			$('#gallerycontrols').css('visibility','visible');
			return false;
		});
		
	
		
		$('#cboxClose').click(function(){
			$('.mp3Controls').css('visibility','hidden')
		});
			
		$('#cboxSlideshow').live("click", function(){
			if($(this).html()=='Start fremvisning'){
				if ($('#player').length>0)
					document.getElementById("player").SetVariable("player:jsPause", "");
			}else{
				if ($('#player').length>0){
					document.getElementById("player").SetVariable("player:jsPlay", "");
				}
			}
		});
		
		//Popup for article images
		/*$('#article img').colorbox({
			 href: function(){
			 		var theurl = $(this).attr('src');
			 		return theurl; //'<a href="'+theurl+'">';
			 	},
			 	photo: true,
			 	height: function(){
			 		return $(this).height()+150;
			 	}
		}).css('cursor', 'pointer');*/
		
		
		$('#novus_searchterms').bind('mousedown blur', function(event){
			if(event.type=='mousedown'){
				if($(this).val().toLowerCase()=='søk i atlas-alliansen'){
					$(this).val('');
				}
			}
			else if(event.type=='blur'){
				if($(this).val()==''){
					$(this).val('Søk i Atlas-alliansen');
				}
			}
		});
		
	});
})();
