$(document).ready(function show(){
	
	//loading background preloader
	var loaderImg = new Image();
	$(loaderImg).load(function () {
		$(this).hide(); //hides the image while it loads
		$('#loading_holder').fadeIn(1000);	
		}).attr('src', 'images/loading_bg.png'); //inserts image source
		
	//first image preloader
	var firstImg = new Image();
	
	$(firstImg).load(function () {
		$(this).hide(); //hides the image while it loads
				
		$('#loading_holder').fadeOut(500);
		$('#project1').html(this); //inserts the image tag into the current project div
    
		$(this).show();//shows the image before the div fades in
		$('#project1').fadeIn(800);//shows the div, with the image loaded
		$('#description').delay(500).fadeIn(800);
		//$('#buy_print_bt').delay(500).fadeIn(800);
		
		$('#video_right_side').fadeIn(800);
		$('#video_left_side').fadeIn(800);
		$('#video_center').fadeIn(800);
		
		$('#next').delay(500).fadeIn(800); //shows next arrow
		
		$('#block').hide();
		$('#menu_block').hide();//unblocks both the menu and arrows
			
		}).error(function () {
			alert('Image could not be loaded');
				
		}).attr('src', 'images/works_1.png'); //inserts image source, and perhaps attributes
	
		/*/==================================================/*/
		/*/Works Gallery/*/
		/*/==================================================/*/
		
		//array with all the project information
		var currentDesc = [	
			['The Undead | 2011', '#', '#'],
			['Stygian Depths | 2010', '#', '#'],
			['Infected Warrior | 2009', 'http://www.deviantart.com/print/7670568/?', '#'],
			['Maze Runner Cover | 2010', 'http://www.deviantart.com/print/19419431/?', '#'],
			['Ruins | 2010', '#', '#'],
			['The Inmortal | 2011', 'http://www.deviantart.com/print/19336515/?', '#'],
			['Inmortals Fight | 2011', 'http://www.deviantart.com/print/19588424/?', '#'],
			['Portal | 2009', '#', '#'],
			['Landscapes | 2011', '#', '#'],
			['Paranormacore Records Logo | 2011', '#', '#'],
			['Creature Sketch | 2011', '#', '#'],
			['Creature Sketch | 2011', '#', '#'],
			['The Underlands | 2011', '#', '#'],
			['Enjoy | 2008', 'http://www.deviantart.com/print/1310408/?', '#'],
			['Maze Runner Cover Sketch | 2010', 'http://www.deviantart.com/print/14189006/?', '#'],
			['Random Sketches | 2011', '#', '#'],
			['Cliff Hanger | 2006', 'http://www.deviantart.com/print/11930841/?', '#'],
			['Stygian Depths Sketches | 2010', '#', '#'],
			['Goblin Sketch | 2010', '#', '#'],
			['Akira Type Poster | 2006', 'http://www.deviantart.com/print/11930786/?', '#'],
			['Abaddon | 2006', 'http://www.deviantart.com/print/5029159/?', '#'],
			['Lich | 2010', 'http://www.deviantart.com/print/3997456/?', '#'],
			['Dream Shore | 2008', 'http://www.deviantart.com/print/2760897/?', '#']
		]
		
		var current = 1;
		
		//Next Project Function
		$('#next').click(function next_project() {
			
			$('#block').show();
			$('#menu_block').show();//blocks both the menu and arrows
			$('#loading_holder').fadeIn(500);
			$('#project'+current).fadeOut (800);
			$('#description').hide();
			
			current++;
			if (current > 21) {	current = 21 } //sets a limit
			
			//hides arrows on limits
			if (current > 1) { $('#back').fadeIn(800); }
			else { $('#back').fadeOut(800); }
			if (current == 21) { $('#next').fadeOut(800); }
			else { $('#next').fadeIn(800); }
			
			var imagePath = 'images/works_'+current+'.png'; //creates the path of the current image
			var img = new Image(); //creates an image tag and loads it to a var
			
			//begins to load current image
			$(img).load(function () {
				  
				$(this).hide(); //hides the image while it loads
				
				$('#loading_holder').fadeOut(500);
				$('#project'+current).html(this); //inserts the image tag into the current project div
    
				$(this).show();//shows the image before the div fades in
				$('#project'+current).fadeIn(800);//shows the div, with the image loaded
				
				//unblocks the menu and arrows
				$('#block').fadeOut(800);
				$('#menu_block').fadeOut(800);
				
				//Updates the #description text
				$('#description').html(''+currentDesc[current-1][0]+'');
				$('#description').fadeIn(800);
				//Updates the prints link
				$('#current_print').attr('href',''+currentDesc[current-1][1]+'');
				
				if (currentDesc[current-1][1] == '#') {
				$('#current_print').hide();
				$('#buy_print_bt').hide();}
				else {
				$('#current_print').show();
				$('#buy_print_bt').show();}
			
			}).error(function () {
				alert('Image could not be loaded');
				
			}).attr('src', ''+imagePath+''); //inserts image source
	});
	
	
	//Prev Project Function
	$('#back').click(function prev_project()
		{
			$('#block').show();
			$('#menu_block').show();//blocks both the menu and arrows
			$('#description').hide();
			
			$('#project'+current).fadeOut (800);
			current = current -1;
			if (current < 1) {current = 1} //sets a limit
			
			//arrow dissapear on limits
			if (current > 1) { $('#back').fadeIn(800); }
			else { $('#back').fadeOut(800); }
			if (current < 21) { $('#next').fadeIn(800); }
			
			$('#project'+current).fadeIn (800);
			
			//unblocks the menu and arrows
			$('#block').fadeOut(800);
			$('#menu_block').fadeOut(800)
			
			//Updates the #description text
			$('#description').html(''+currentDesc[current-1][0]+'');
			$('#description').fadeIn(800);
			//Updates the prints link
			$('#current_print').attr('href',''+currentDesc[current-1][1]+'');
				
			if (currentDesc[current-1][1] == '#') {
				$('#current_print').hide();
				$('#buy_print_bt').hide();}
			else {
				$('#current_print').show();
				$('#buy_print_bt').show();}
			});
		
		
	/*/==================================================/*/
	/*/ Section Selector /*/
	/*/==================================================/*/

	var currentSection = 1;

	$('#link_works').click(function sectionWorks () {
	
		$('#block').show();
		$('#menu_block').show();//blocks both the menu and arrows
		
		if (currentSection = 2) {
			$('#about').fadeOut (1000);
			$('#link_about').removeClass ('menu_selected')
			}
			
		if (currentSection = 3) {
			$('#contact').fadeOut (1000);
			$('#link_contact').removeClass ('menu_selected')		
			}
			
		$('#link_works').addClass ('menu_selected')
		$('#works').fadeIn (1000);
			
		currentSection = 1 /*/ Section Works Selected /*/
		
		$('#block').fadeOut(1000);
		$('#menu_block').fadeOut(1000);//unblocks both the menu and arrows
		});


	$('#link_about').click(function sectionAbout () {
	
		$('#block').show();
		$('#menu_block').show();//blocks both the menu and arrows	
	
		if (currentSection = 1) {
			$('#works').fadeOut (1000);
			$('#link_works').removeClass ('menu_selected')
			}
			
		if (currentSection = 3) {
			$('#contact').fadeOut (1000);
			$('#link_contact').removeClass ('menu_selected')	
			}
		
		$('#link_about').addClass ('menu_selected')
		$('#about').fadeIn (1000);
		currentSection = 2 /*/ Section About Selected /*/
		
		$('#block').fadeOut(1000);
		$('#menu_block').fadeOut(1000);//unblocks both the menu and arrows
		});
	

	$('#link_contact, #about_contact').click(function sectionContact () {
	
		$('#block').show();
		$('#menu_block').show();//blocks both the menu and arrows
		
		if (currentSection == 1) {
			$('#works').fadeOut (1000);
			$('#link_works').removeClass ('menu_selected');
			}
			
		if (currentSection == 2) {
			$('#about').fadeOut (1000);
			$('#link_about').removeClass ('menu_selected');
			}
		
		$('#link_contact').addClass ('menu_selected');
		$('#loading_holder').fadeIn(500); //displays loading
		
		var contactBg = new Image(); //creates an image holder for the #contact_bg background
		
		$(contactBg).load(function () {
			
				$(this).hide(); //hides the background until it loads
				
				//preloads the submit button background
				var submitBg = new Image();				
				$(submitBg).load(function () {
					$(this).hide();
					}).attr('src', 'images/send.jpg');
					
				//preloads the thanks message
				var submitThanks = new Image();				
				$(submitBg).load(function () {
					$(this).hide();
					}).attr('src', 'images/thanks.png');
				
				$('#loading_holder').fadeOut(500);
				$('#contact_bg').html(this); //inserts the image tag into the current project div
    
				$(this).show();//shows the image before the div fades in
				$('#contact').fadeIn(800);//shows the section, with the image loaded in #contact_bg
				
				$('#block').fadeOut(1000);
				$('#menu_block').fadeOut(1000);//unblocks both the menu and arrows
			
			}).error(function () {
				alert('Image could not be loaded');
			}).attr('src', 'images/contact_bg.jpg'); //inserts image source
		
		currentSection = 3 // Section Contact Selected	
		
		});
	
});

