﻿$(window).bind("load",function(){
				$(".left_column").fadeIn(1000);
		//Show Home Box when page loads
		focusCurrent("div.side_links a","div#box1");
				
		//Create Actual Links
		$("a").click(function(){
			if($(this).attr("href") == "#"){
				return false;
			}
		})
		
		//Reply Situation
					$(".reply").fadeTo(400, 1).fadeTo(400, .01).slideUp("normal");
				
		//Clicking On Links - Fade Out All .main Divs, delay everything for 500 ms, Fade Links to half opacity, Fade In Current Link, Fade In Current Content Box
		var fadeable = 1;
		function hidePlinks(){
			$("div.side_links_mini").slideUp("slow").dequeue()
		}
		function fadeMains(){
			$("div.main").fadeOut(500);
			$("#space").hide();
		}
		function fadeSideLinks(){
			$("div.side_links a").fadeTo(250, .5).dequeue()
		}
		function focusCurrent(l,b){
			$(l).fadeTo(250, 1)
			$(b).css("position", "absolute").css("max-width", "570px").fadeTo(500, 0).fadeTo(500, 1, function(){ fadeable = 1; })
		}
		function fadeIcons(){
			$("div.icon_holder").fadeTo(250, .95);
		}
		function showPage(l, p){
			if(fadeable == 1){
				fadeable = 0;
				$(this).dequeue()
				fadeMains();
				hidePlinks()
				fadeSideLinks()
				focusCurrent(l, p);
				$("#space").slideDown(100, function(){
					var spaceHeight = $(p).height() + 85 + "px";
					$("#space").css("height", spaceHeight);
				});
			}
		}
		function showPanel(p){
			$(this).dequeue()
			fadeMains()
			hidePlinks()
			fadeSideLinks()
			$(p).fadeIn("slow", function(){
				$("#space").slideDown(100, function(){
					var spaceHeight = $(p).height() + 85 + "px";
					$("#space").css("height", spaceHeight);
				});
			})
		}
		
				$("a#link1").click(function(){
			showPage("div.side_links a","div#box1")
					})
				$("a#link2").click(function(){
			showPage("a#link2","div#box2")
						$("div.side_links_mini").slideDown("slow")
					})
				$("a#link3").click(function(){
			showPage("a#link3","div#box3")
					})
				$("a#link4").click(function(){
			showPage("a#link4","div#box4")
					})
				$("a#link5").click(function(){
			showPage("a#link5","div#box5")
					})
				
		$("div.login").fadeTo(1000, .85);
		$("div.login").hover(
			function(){
				$(this).fadeTo(200, 1).dequeue();
			},
			function(){
				$(this).fadeTo(200, .85).dequeue();
			}
		);
				
		//Portfolio Subs
					$("a#link__cat_1").click(function(){
				if(fadeable == 1){
				fadeable = 0;
					$(this).dequeue()
					fadeMains()
					fadeSideLinks()
					fadeIcons()
					focusCurrent("a#link__cat_1","div#box__cat_1");
				}
			})
						$("a#link__cat_2").click(function(){
				if(fadeable == 1){
				fadeable = 0;
					$(this).dequeue()
					fadeMains()
					fadeSideLinks()
					fadeIcons()
					focusCurrent("a#link__cat_2","div#box__cat_2");
				}
			})
						$("a#link__cat_3").click(function(){
				if(fadeable == 1){
				fadeable = 0;
					$(this).dequeue()
					fadeMains()
					fadeSideLinks()
					fadeIcons()
					focusCurrent("a#link__cat_3","div#box__cat_3");
				}
			})
						$("a#link__cat_4").click(function(){
				if(fadeable == 1){
				fadeable = 0;
					$(this).dequeue()
					fadeMains()
					fadeSideLinks()
					fadeIcons()
					focusCurrent("a#link__cat_4","div#box__cat_4");
				}
			})
						
			$("a#link__cat_5").click(function(){
				if(fadeable == 1){
				fadeable = 0;
					$(this).dequeue()
					fadeMains()
					fadeSideLinks()
					fadeIcons()
					focusCurrent("a#link__cat_5","div#box__cat_5");
				}
			})
					$("div.icon_holder").mouseover(function(){
			$(this).fadeTo(150, .6).dequeue()
		})
		$("div.icon_holder").mouseout(function(){
			$(this).fadeTo(400, 1).dequeue()
		})
		
		//Show Settings
		$("a#link_dropdown").hover(
			function(){
				$("#dropdown").show();
			},
			function(){
				$("#dropdown").hide();
			}
		); 
		$("#dropdown").hover(
			function(){
				$("#dropdown").show();
			},
			function(){
				$("#dropdown").slideUp("fast");
			}
		); 
		
		
		//Add To Portfolio
				$("a#link_add").click(function(){
			showPanel("div#box_add")
		})
		
		//Change Customization Options
		$("a#link_customize").click(function(){
			showPanel("div#box_customization")
		})
				
		//Change Settings and Info
		$("a#link_settings").click(function(){
			showPanel("div#box_settings")
		})
				
		//Manage Portfolio
		$("a#link_manage").click(function(){
			showPanel("div#box_manage")
		})
				
		//Changing Pages
		$("a#link_pages").click(function(){
			showPanel("div#box_pages")
		})
				
		//Editing Names of Pieces
		$("span.managelist_title").click(function(){
			if(editable == 1){
				editable = 1;
				var title = $(this).text();
				title_ = title.split('(ID-EDIT-NUM)');
				var id = title_[0];
				//Replace with input box
				$(this).replaceWith('<div style="height:18px;left:18px;top:-20px;position:relative;"<form name="editTitle" action="" enctype="multipart/form-data" method="post"><input name="title_form" type="text" value="' + title_[1] + '" /> <select id="type" name="type"><option selected="selected" value="">Please Choose A Category &nbsp;&nbsp;</option><option disabled="disabled">&nbsp;</option><option value="Artwork">Artwork</option><option value="Identity">Identity</option><option value="Illustration">Illustration</option><option value="Photography">Photography</option><option value="Web Designs">Web Designs</option><option disabled="disabled">&nbsp;</option><option value="Animation" id="animation_select">Animation (Beta)</option></select> <input name="id" type="hidden" value="' + id + '" /> <input name="editButton" class="curved button" type="submit" value="Save" /><br/><textarea style="height:30px; width:362px" name="descrip_form">'+ title_[2] +'</textarea></form></div');
			}
			
		})
		var editable = 1;
		
		//Hide div w/id extra
        $("#preview").css("display","none");
        $("#type").click(function(){
			if ($("#animation_select").is(":selected")){
				$("#preview").slideDown("normal");
			} else {
				$("#preview").slideUp("normal");
			}
		});
		
		//Login Box
		login_shown = 1;
		$("div.login a#toggle_login").click(function(){
			if(login_shown == 1){
				$("div.login_box").fadeIn("normal");
				$("a#toggle_login").fadeTo(200, .3);
				login_shown = 0;
			} else {
				$("div.login_box").fadeOut("normal");
				$("a#toggle_login").fadeTo(200, 1);
				login_shown = 1;
			}
		})
	});
	
	//Lightbox Viewer
	$(document).ready(function(){
		//When you click on something with class, lightbox, it adds the overlay and shows the file that the a href was linked to.
		$(".lightbox").click(function(){
			overlayLink = $(this).attr("href"); //Show What's in the link
			title = $(this).attr("title"); //Grab the title
			string = $(this).next(".info").text(); //Get the parent div's p which contains the date
			elements = string.split("+br");
			//window.startOverlay(overlayLink, title, elements[0], elements[3]); //Execute the lightbox
			window.startOverlay(overlayLink, title, '',$(this).attr('id'), elements[3]); //Ankita
			return false; //Tells the browser to not actually go to the link when clicked on the a href
		});
	});
	$(document).ready(function(){
		$(".lightboxSWF").click(function(){
			overlayLink = $(this).attr("href"); //Show What's in the link
			title = $(this).attr("title"); //Grab the title
			string = $(this).next(".info").text(); //Get the parent div's p which contains the date
			elements = string.split("+br");
			window.startOverlaySWF(overlayLink, title, elements[0], elements[1], elements[2]); //Execute the lightbox
			return false; //Tells the browser to not actually go to the link when clicked on the a href
		});
	});
	
	//Image Lightbox
	function startOverlay(overlayLink, title, date, id, overlay) {
		//Adds the overlay layer plus the container layer, which will contain the image and text
		if(overlay != 0){
			$("body").append('<div class="overlay"><span class="close"></span></div><div class="container"></div>')
		} else {
			$("body").append('<div class="container"></div>')
		}
	
		//Animates the transparent black sheet covering the screen
		$(".overlay").animate({"opacity":"0.85"}, 450, "linear");
	
		//Puts the image, title and date into the .container depending on browser type
		if($.browser.msie && $.browser.version < 9.0){
			$(".container").html('<img src="'+overlayLink+'" alt="" /><div><p>'+title+'<br /><span>'+date+'</span></p></div>');
		} else {
			$(".container").html('<p class="captionholder"><span class="nav navLeft"></span><span class="nav navRight"></span><img src="'+overlayLink+'" alt="" /><div class="caption"><p>'+title+'<br /><span>'+date+'</span></p></div></p>');
		}
		
		//Alows for the removal of the lightbox.
		window.removeOverlay(id);
		
		//Preload
		var nextPiece = $("#piece_"+id).next("div").children("a.lightbox");
		nextImage = new Image();
		nextImage.src = nextPiece.attr("href");
		var prevPiece = $("#piece_"+id).prev("div").children("a.lightbox");
		prevImage = new Image();
		prevImage.src = prevPiece.attr("href");
		
		//Position the image accordingly.
		$(".container img").load(function() {
			var imgWidth = $(".container img").width() + 2; //Plus 2 for the border
			var imgHeight = $(".container img").height() + 2; //Plus 2 for the border
			if( ($(window).height() / 2) > ((imgHeight / 2) + 30) ){
				var containerHeight = "50%";
			} else {
				var containerHeight = (imgHeight / 2) + 30;
			}
			$(".container").css({
				"top": containerHeight,
				"left": "50%",				
				"width": imgWidth,
				"height": imgHeight + 30,
				"margin-top": -(imgHeight/2),
				"margin-left":-(imgWidth/2) //Position the image in the middle of the screen.
			}).animate({"opacity":"1"}, 550, "linear", function(){
				$(".overlay").css({"background-image": "none"});
			});
			
			//Make necessary changes for IE
			if($.browser.msie && $.browser.version < 9.0){
				$(".overlay").css({"height": "150%"});
				$(".container div").css({"padding-left": "6px"});
				$(".container").css({"height": imgHeight + 50});
			}
			
			//Make Page Longer
			var spaceHeight = imgHeight + 350;
			$("#space").css("height", spaceHeight);
		
			//Show the actual image and hide stuff		
			$(".container div").fadeTo(1250, 1).fadeTo(1000, .001); //Hide the comment after a while.
			//Hover over the comment above.
			$(".container div").hover(
				function(){
					$(this).fadeTo(300, 1).dequeue();
				},
				function(){
					$(this).fadeTo(300, .001).dequeue();
				}
			); 
			//Hover Over Nav Links
			$("span.nav").hover(
				function(){
					$(this).fadeTo(200, 1).dequeue();
				},
				function(){
					$(this).fadeTo(200, .001).dequeue();
				}
			); 
		});
	}
	
	//SWF Lightbox
	function startOverlaySWF(overlayLink, title, date, widthpop, heightpop) {
		var imgWidth = widthpop; //Plus 2 for the border
		var imgHeight = heightpop; //Plus 2 for the border
		
		//Adds the overlay layer plus the container layer, which will contain the image and text
		$("body")
			.append('<div class="overlay"></div><div class="container"></div>');
			
		
		//Animates the transparent black sheet covering the screen
		$(".overlay").animate({"opacity":"0.85"}, 450, "linear");
		
		//Puts the image, title and date into the .container
		$(".container").html('<div><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0" id="Flash" width="'+imgWidth+'" height="'+imgHeight+'"> <param name="allowScriptAccess" value="sameDomain"><param name="movie" value="'+overlayLink+'"><param name="quality" value="high"><embed src="'+overlayLink+'" quality="high" width='+imgWidth+' height='+imgHeight+' name="Flash" allowscriptaccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></object></div><div id="titles"><p>'+title+'<span>'+date+'</span></p></div>');
		//$(".container").html('<div><object width="imgWidth" height="imgHeight"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=15775424&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=1&amp;color=&amp;fullscreen=1&amp;autoplay=0&amp;loop=0" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=15775424&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=1&amp;color=&amp;fullscreen=1&amp;autoplay=0&amp;loop=0" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="300"></embed></object>');
		//$(".container").html('<div> <embed width='+imgWidth+' height='+imgHeight+' quality=high name= flvvideo id=flvvideo src='+overlayLink+' type=application/x-shockwave-flash> </div><div id="titles"><p>'+title+'<span>'+date+'</span></p></div>');
        
  
		//Alows for the removal of the lightbox.
		window.removeOverlay();
		
		//Position the image accordingly.
		$(".container").css({
			"top": "50%",
			"left": "50%",				
			"width": imgWidth,
			"height": imgHeight,
			"margin-top": -(imgHeight/2),
			"margin-left":-(imgWidth/2) //Position the image in the middle of the screen.
		}).animate({"opacity":"1"}, 550, "linear", function(){
			$(".overlay").css({"background-image": "none"});
		}); //Show the actual image.		
		$(".container div#titles").fadeTo(2000, 1).fadeTo(1000, .001); //Hide the comment after a while.
		$(".container div#titles").hover(
			function(){
				$(".container div#titles").fadeTo(300, 1).dequeue();
			},
			function(){
				$(".container div#titles").fadeTo(300, .001).dequeue();
			}
		); //Hover over the comment above.
	}
	
	//Remove Lightbox
	function removeOverlay(id) {
		// When the user clicks on the overlay, the lightbox goes away.
		$(".overlay, .container img").click(function(){
			$(".container, .overlay").animate({"opacity":"0"}, 250, "linear", function(){
				$(".container, .overlay").remove();	
			});
		});
		var k = (id*1) +1;
		//Click Next or Previous
		$("span.navRight").click(function(){
			//var nextPiece = $("#piece_"+id).next("div").children("a.lightbox");
			var nextPiece = $("#piece_"+k).children("a.lightbox");  //Ankita
			if(nextPiece.attr("href") === undefined){
				$(".container, .overlay").animate({"opacity":"0"}, 250, "linear", function(){
					$(".container, .overlay").remove();	
				});
			} else {
				overlayLink = nextPiece.attr("href"); //Show What's in the link
				title = nextPiece.attr("title"); //Grab the title
				string = nextPiece.next(".info").text(); //Get the parent div's p which contains the date
				elements = string.split("+br");
				$(".container").fadeTo(400, 0, function(){
					$(this).remove();
					//window.startOverlay(overlayLink, title, elements[0], elements[3], 0); //Execute the lightbox
					window.startOverlay(overlayLink, title, '',$("#"+k).attr('id'), elements[3]); //Ankita
				})
			}
		})
		$("span.navLeft").click(function(){
			//var nextPiece = $("#piece_"+id).prev("div").children("a.lightbox");
			 var k = (id*1) -1;
		    var nextPiece = $("#piece_"+k).children("a.lightbox");
		    
			if(nextPiece.attr("href") === undefined){
				$(".container, .overlay").animate({"opacity":"0"}, 250, "linear", function(){
					$(".container, .overlay").remove();	
				});
			} else {
				overlayLink = nextPiece.attr("href"); //Show What's in the link
				title = nextPiece.attr("title"); //Grab the title
				string = nextPiece.next(".info").text(); //Get the parent div's p which contains the date
				elements = string.split("+br");
				$(".container").fadeTo(400, 0, function(){
					$(this).remove();
					//window.startOverlay(overlayLink, title, elements[0], elements[3], 0); //Execute the lightbox
					window.startOverlay(overlayLink, title, '',$("#"+k).attr('id'), elements[3]);  //Ankita
				})
			}
		})
	}
