$(document).ready(function(){

//------------------------------------------------------------------------------------------------//
//define var for currentSection
var currentURL = location.pathname.substring(1); //get URL of current page

var lastSlashPos = currentURL.lastIndexOf('/'); //determine location of last slash - filename start
var lastDotPos = currentURL.lastIndexOf('.'); //determine location of last dot - filename extension start
var currentSection = currentURL.slice(lastSlashPos+1,lastDotPos); //extract just filename without ext == section name
//------------------------------------------------------------------------------------------------//

//------------------------------------------------------------------------------------------------//
//HIDE ADMIN ELEMENT
//$('#admin_login form').hide();

//HIDE PAUSE BUTTONS
$('.pause_button').hide();
//------------------------------------------------------------------------------------------------//

//------------------------------------------------------------------------------------------------//
//HIDE DISCOGRAPHY PANE BUTTON CODE
$('#hide_discography_link').click(function(){ 
		
	$('#discography_text').hide();	
		
});//end $('#admin_login').click

$('#discography_show_link').click(function(){ 
		
	$('#discography_text').show();	
		
});//end $('#admin_login').click

//------------------------------------------------------------------------------------------------//

//------------------------------------------------------------------------------------------------//
function onm_edit_mode_css(){
	
	
	
	/*
	if($('#admin_login').attr('id') != undefined){
	
		
		var currentLocation = location.href;
		
		//alert(currentLocation);
		
		var lastColon = currentLocation.lastIndexOf(':');
		
		//alert(lastColon);
		
		var locationStripped = currentLocation.slice(lastColon);
		var currentProtocol = currentLocation.slice(0,lastColon);
		//alert(currentProtocol);
		
		if(currentProtocol != 'https'){
			//alert(locationStripped);
			
			var newLocation = 'https' + locationStripped;
			
			//alert(newLocation);
			
			location = newLocation;
			
		};//end if(currentProtocol != 'https')
	
	};//end if($('#admin_login') != false)
	*/

	
	if($('#admin_logout').attr('id') != undefined){
	
		
		if($('#music_player').attr('id') != undefined){
		
			$('.music_inner_box').css({
			
			'height':'auto'
			
			}); //make sure height is no longer restricted on music page layout
		
		}; //end if($('#music_player').attr('id') != undefined)
		
	
		
	
	};//end if($('#admin_login') != false)
	
	

/*$('#admin_login').click(function(){ 
	
	var currentProtocol = location.protocol;
	
	//alert(currentProtocol);
	
	if(currentProtocol != 'https:'){
	
		location.protocol = 'https:';
		
	}; //end if(currentProtocol == 'http:')
	
	$('#admin_login form').show();	
		
});//end $('#admin_login').click*/

};//end function onm_edit_mode_css()


onm_edit_mode_css();
//------------------------------------------------------------------------------------------------//


//------------------------------------------------------------------------------------------------//
//This function highlights the current page link in hardcoded style and makes sure its parent submenu stays open
var currentLinkID = '#' + currentSection + '_link'; //derive link ID from filename

//Target element
var currentLink = $(currentLinkID); //select current link
	
currentLink.css({
	
	'color':'#666666'

}); //set current link style
//currentLink.css('fontWeight','bold'); //set current link style

//------------------------------------------------------------------------------------------------//

//------------------------------------------------------------------------------------------------//
//LINK HELPER CODE
$('#link_helper_form').submit(function() {

	
	var linkText = $('#link_text').attr('value');
	var linkHref = $('#link_href').attr('value');
	
	var linkHtml = '<a href="'+linkHref+'">'+linkText+'</a>';
	  
	$('#link_helper_answer').text(linkHtml).html();
	  
	return false;
});
//------------------------------------------------------------------------------------------------//

//------------------------------------------------------------------------------------------------//
//IMAGE HELPER CODE
$('#image_helper_form').submit(function() {

	
	var imageText = $('#img_alt').attr('value');
	var imageSrc = $('#img_src').attr('value');
	
	var imageHtml = '<img src="'+imageSrc+'" alt="'+imageText+'" />';
	  
	$('#image_helper_answer').text(imageHtml).html();
	  
	return false;
});
//------------------------------------------------------------------------------------------------//


//------------------------------------------------------------------------------------------------//
//PULL IN BACKGROUND IMAGE FROM DATABASE AND APPLY CSS
//background-image: url($simpleSrcString);

var imageSrcString = $('#index_bg span').attr('class');

$('#index_content').css({
	
	
	'background-position': '0px 100px',
	'background-repeat': 'no-repeat',
	'position': 'relative',
	'background-image': 'url('+imageSrcString+')'

}); //end $('#index_content').css

//------------------------------------------------------------------------------------------------//

//------------------------------------------------------------------------------------------------//
var imageIndex; //index of currently active viewer image
var imagePath; //current small image src attribute (called from mouseover on small images)
var fileName;

function onm_current_image_parameters(){ //imagePath is the path of the desired large image to inspect, sets above variables so they can be accessed from other functions
	
	if(imagePath != undefined){ //as in first page load!!
	
		//var lastSlash = imagePath.lastIndexOf('/'); //determine location of last slash - filename start
		//var lastDot = imagePath.lastIndexOf('.') //determine location of last dot - filename extension start
		//var fileName = imagePath.slice(lastSlash+1,lastDot); //extract just filename without ext
		fileName = imagePath;
		
		//alert(fileName); //debug step
		
		lastUnscor = fileName.lastIndexOf('_'); //determine location of last underscore - _s.jpg start
		
		fileName = fileName.slice(0,lastUnscor);
		
		//alert(fileName); //debug step
		
		lastUnscor = fileName.lastIndexOf('_'); //determine location of last underscore - index start
		//lastDot = fileName.lastIndexOf('.') //determine location of last dot - filename extension start
		imageIndex = fileName.slice(lastUnscor+1); //extract just index
		
		//alert(imageIndex); //debug step
		

	}; //end if(imagePath != undefined)
	
}; //end function onm_current_image_parameters()
//!!!NOTE FOR THE FUTURE - IE6 IN WINDOWS DOES NOT EXECUTE GET REQUEST LOCALLY AND CODE WILL FAIL - UPLOAD AND ALL IS WELL!!!
//------------------------------------------------------------------------------------------------//


//------------------------------------------------------------------------------------------------//
//VIEWER IMAGE SWAPPING CODE
$('#photo_viewer img').hide();// hide all viewer images at page load
$('#photo_viewer img:first').show(); // show first image in div
$('#photo_viewer form').hide();
$('#photo_viewer form:first').show();


$('#photo_thumbs img').mouseover(function(event){ //selector must define event handler on elements existing at document load, event object passes the image mouse event is triggered on

		var target = $(event.target);
		
		if(target.attr('id') != undefined){ //unless the target has no attribute "id"
			
			imagePath = target.attr('id'); //full path of image
			
			onm_current_image_parameters();
			
			$('#photo_thumbs img').css({ //make sure all image borders are default
				
				'border-color':'#7e7e7e'
			
			}); // end $('#photo_thumbs img').css
			
			target.css({ //active image thumb style
				
				'border-color':'#ffffff'
			
			}); // end $('#photo_thumbs img').css
			
			//var photoViewerHtml = '<img id="photo_viewer_image" src="images/image_' + imageIndex + '.jpg" alt="image_' + imageIndex + '" width="1000" height="590" />';
			
			//$('#photo_viewer').html(photoViewerHtml);
			
			$('#photo_viewer img').hide();
			$('#photo_viewer form').hide();

			$('#' + fileName).show();
			$('#image_upload_form_' + imageIndex).show();
			
			
		}; //end if(target.attr('src') != undefined && $('#thumbs_table').attr('class').indexOf('ui-draggable-dragging') == -1)
		
	});//end $('#image_viewer_thumbs img').mouseover(function(event)
//------------------------------------------------------------------------------------------------//

//------------------------------------------------------------------------------------------------//
//ACTIVATE MUSIC PLAYER
$('#music_player img').click(function(event){ //event object passes the object mouse event is triggered on

		var target = $(event.target);
		
		//var trackName = target.attr('id'); //id of image
		var imageID = target.attr('id'); //id of image
		
		lastUnscor = imageID.lastIndexOf('_'); //determine location of last underscore - _s.jpg start
		
		uniqueAudioID = imageID.slice(lastUnscor+1);
		
		var imageSrc = target.attr('src'); //src of image
		
		//alert(imageSrc == 'images/play.jpg');
		
		var musicPlayerHtml;
		
		//var imageState;
		
		if(imageSrc == 'images/play.jpg'){ //if play button is available == nothing is playing on that track...
			
			//alert('if code is running...');
			$('#music_player span').css({
			
				'color':'#fae6c3'
			
			}); //end $('#music_player img').css
		
		
			
			
			$('#track_title_' + uniqueAudioID).css({
			
				'color':'#666666'
			
			}); //end $('#music_player img').css
			
			//'<audio id="html5_player" src="tracks/' + trackName + '.mp3" controls="controls" autoplay="autoplay"></audio>'
			
			
			
			if($.browser.webkit){
			
      			musicPlayerHtml = '<audio id="html5_player" src="retrieve_audio.php?uniqueAudioID=' + uniqueAudioID + '" controls="controls" autoplay="autoplay"></audio>';
      			
      			    			  			
  			 }else{
  			 
  			 	musicPlayerHtml = '<embed src="retrieve_audio.php?uniqueAudioID=' + uniqueAudioID + '" width=380 height=20>';
      			
   			};
			
			$('#player_container').html(musicPlayerHtml);
			
			$('.pause_button').hide();
			$('.play_button').show();
			
			$('#pause_button_' + uniqueAudioID).show();
			$('#play_button_' + uniqueAudioID).hide();
			
			//alert($('#play_button_' + uniqueAudioID).attr('src'));
			
		};//end if(imageSrc == 'images/play.jpg')
		
		if(imageSrc == 'images/pause.jpg'){ //if pause button is available == something is playing on that track...
			
			$('#music_player span').css({
			
				'color':'#fae6c3'
			
			}); //end $('#music_player img').css
		
		
			$('.pause_button').hide();
			$('.play_button').show();
			
			musicPlayerHtml = '';
			
			$('#player_container').html(musicPlayerHtml);
			
		};//end if(imageSrc == 'images/pause.jpg')
		
		
		
});//end $('#music_player img').click

//------------------------------------------------------------------------------------------------//


}); //end $(document).ready
