(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)

$.ajaxSetup({cache: false});

var img;
var webaddress = "http://" + window.location.hostname;

jQuery.preLoadImages("/layout/background.jpg",
					"/layout/previous_over.png",
					"/layout/next_over.png",
					"/layout/previous.png",
					"/layout/next.png",
					"/layout/load.gif",
					"/layout/portload2.gif",
					"/layout/fbook_over.png",
					"/layout/linkedin_over.png",
					"/layout/twitter_over.png",
					 "/layout/blog_over.png",
					 "/layout/portfolio_over.png",
					 "/layout/contact_over.png"
					);


function findSize () {
	if (typeof window.innerWidth != 'undefined')
	{
		viewportwidth = window.innerWidth,
		viewportheight = window.innerHeight
	}

//	IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

	else if (typeof document.documentElement != 'undefined'
		&& typeof document.documentElement.clientWidth !=
			'undefined' && document.documentElement.clientWidth != 0)
	{
		viewportwidth = document.documentElement.clientWidth,
		viewportheight = document.documentElement.clientHeight
	}

//	older versions of IE

	else
	{
		viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
		viewportheight = document.getElementsByTagName('body')[0].clientHeight
	}


}

function lightboxpr (title, client, imgsrc) {
	
	
	findSize();
	viewportwidth = Math.round(viewportwidth/2);
	viewportheight = Math.round(viewportheight/2);
	
	var top, left;
	
	top = viewportheight - (Math.round(40/2));
	left = viewportwidth - (Math.round(200/2));
	
	$("#lightbox").css({'top' : top+'px',
		'left' : left+'px',
		'width' : '200px',
		'height' : '40px'});
	
	//top = viewportheight - (Math.round(boxHeight/2));
	//left = viewportwidth - (Math.round(boxWidth/2));
	
	$("#lightbox").css({'display' : 'block'});
	
	
	
	
	
	$("#overlay").fadeTo(600, 0.8);
	
	$(".loadinglb").fadeIn("slow", function() {
	
	img = new Image();
	img.src = "";
	img.src = imgsrc + "?" + new Date().getTime();
	
	$(img).load(function() {
	
	$("#lbcontent").html("<img src=\""+img.src+"\" />");
	//$("#lbcontent").css({'display' : 'block'});
	
	
	

	
	top = viewportheight - (Math.round(img.height/2));
	
	if (top < 0) { top = 20 }
	left = viewportwidth - (Math.round(img.width/2));
	
	$(".loadinglb").fadeOut("slow", function() {
		
		
		
		$("#lightbox").animate({'top' : top+'px',
			'left' : left+'px',
			'width' : img.width+'px',
			'height' : img.height+'px'}, 10, function() {
				
				
				
				$("#lbcontent").fadeIn("slow");
				
				
				
			});
		
		
		
		
		
		
	});
	
	});
	
	});
	//$("#overlay").fadeIn("slow");
	
	/*
	
	
	
	 
	$.ajax({
		type: "get",url: "content_lightbox.php",data: z[1],
		beforeSend: function(){
			$(".loadinglb").fadeIn("slow");
			}
			, //show loading just when link is clicked
			
		
		success: function(html){ //so, if data is retrieved, store it in html
				
					conHtml = html;
					
					
			}, //stop showing loading when the process is complete
			
			complete: function(){ 
				
				$(".loadinglb").fadeOut("slow", function() {
					
					$("#lightbox").animate({'top' : top+'px',
						'left' : left+'px',
						'width' : boxWidth+'px',
						'height' : boxHeight+'px'});
					$("#lbcontent").html(conHtml);
					$("#lbcontent").fadeIn("slow");
					$("#lbclose").fadeIn("slow");
					$("#lbcontent").html(conHtml);
					
					
					});
				
				
				} // no real purpose right now but keeping for future
		}); //close ajax
		*/
}


function closelb () {
	
	
	$("#lightbox").stop(true, true); 
	
	

	$("#overlay").fadeOut("slow");
	$("#lightbox").css("display","none");
	$("#lbcontent").css("display","none");
	$("#lbclose").css("display","none");
	img.src = "";
	
	
}




jQuery(document).ready(function($)
{  

	
	$('[rel=lightbox]').live("click", function(event) {
		
		lightboxpr($(this).attr("title"), $(this).attr("name"), $(this).attr("href"));
		event.preventDefault();
		
		
	});
	
	$("#overlay, [rel*=closelb], #lightbox").live("click", function(event) {
		
		closelb();
		
	});
	
	$('.ro').live("mouseenter", function(){
	 		        t = $(this);
	 		       if (!t.hasClass("current")) {
	 		    	  t.attr('src',t.attr('src').replace(webaddress, ""));
	 		    	   t.attr('src',t.attr('src').replace(/([^.]*)\.(.*)/, "$1_over.$2"));
	 		       }
	 		    });
	$('.ro').live("mouseleave", function(){ 
	 		        t = $(this);
	 		        if (!t.hasClass("current")) {
	 		        	t.attr('src',t.attr('src').replace(webaddress, ""));
	 		        	t.attr('src',t.attr('src').replace('_over',''));
	 		        }
	});
	
	$('.portspotimage').live("mouseenter", function(){
				$('.portspotmag').css("display", "block");
	    });
	$('.portspotimage').live("mouseleave", function(){ 
				$('.portspotmag').css("display", "none");
	});
	
	$('#secondarymenu a').live("click", function(event) {
		
		if (!annmain) {
		
		$("#secondarymenu a").removeClass("current");
		$(this).addClass("current");
		
		}
	});
	
	
	
	var annmain = false;
	
$('#menu a, #header a, #leftfoot a, [rel=selfsec]').live("click", function(event) { //start function when menu link is clicked
 		
		if (!annmain) {
				
		var content_show = $(this).attr("href"); //retrieve link data so we can send to content_main.php
		
		content_show = content_show.replace(webaddress,'');
		var x = content_show.split("/");
		 
		 var datastring = "";
		 var i=0;
		 for (i=0;i<x.length;i++)
		 {

			 if (i == 1) {
				
				 datastring += "p="+x[i];
				 
			 }
			 else if (i == 2) {
				
				 datastring += "&s="+x[i];
				 
			 }
			 
			 
		 }
		
		 $("#secondarymenu").fadeOut("slow", function() {
		 
			$.ajax({
				type: "get",url: "/secmenu_load.php", data: datastring,
				//beforeSend: function(){
					
				//	}
				//	, //show loading just when link is clicked
					
				//complete: function(){ 
				//		}, // no real purpose right now but keeping for future
				success: function(html){ //so, if data is retrieved, store it in html
						
							$("#secondarymenu").html(html);
							$("#secondarymenu").fadeIn("slow");
																	
							
							
							
					} //stop showing loading when the process is complete
								
				}); //close ajax
		 });
		}
		
	});
	
	
	
	$('#menu a, #header a, #leftfoot a').live("click", function(event) { //start function when menu link is clicked
 		
	
		if (!annmain) {
		//$("*").stop(true);
		$("#menu img").each(function(index) {

			$(this).attr('src',$(this).attr('src').replace('_over',''));
			$(this).removeClass("current");
		
		});
		
		if ($("#menu [rel="+$(this).attr("rel")+"] img").length > 0){
		  
			$("#menu [rel="+$(this).attr("rel")+"] img").attr('src',$("#menu [rel="+$(this).attr("rel")+"] img").attr('src').replace(/([^.]*)\.(.*)/, "$1_over.$2"));
		}
		
		
		$("#menu [rel="+$(this).attr("rel")+"] img").addClass("current");
		
		$("#leftfoot a").removeClass("current");
		$("#leftfoot a[rel="+$(this).attr("rel")+"]").addClass("current");
		
		
		
		
		
		}
		
	});
	
	
	$('#menu a, #header a, #leftfoot a, #secondarymenu a, [rel=self], [rel=selfsec]').live("click", function(event) { //start function when menu link is clicked
 		
	
		
	  if (!annmain) {
		annmain = true;
		//$("*").stop(true);
		 var content_show = $(this).attr("href"); //retrieve link data so we can send to content_main.php
		 
		 content_show = content_show.replace(webaddress,'');
		 var x = content_show.split("/");
		 
		 
		 var datastring = "";
		 var i=0;
		 for (i=0;i<x.length;i++)
		 {

			 if (i == 1) {
				
				 datastring += "p="+x[i];
				 
			 }
			 else if (i == 2) {
				
				 datastring += "&s="+x[i];
				 
			 }
			 else if (i == 3) {
					
				 datastring += "&id="+x[i];
				 
			 }
			 
			 
		 }
		
		
		var loadheight = $("#contentloaded").outerHeight();
				
		$("#contentholder").css("height",loadheight); 
		$("#contentloaded").fadeTo("fast", 0, function() {
			
			//$("#contentloaded").css("display","none");
			$("#contentloading").fadeTo("fast", 1.0, function() {
			
				//$("#contentloading").css("display","block"); 
				$.ajax({
				type: "get", cache: false, url: "/content_load.php", data: datastring,
				//beforeSend: function(){
					
				//	}
				//	, //show loading just when link is clicked
					
				//complete: function(){ 
				//		}, // no real purpose right now but keeping for future
				success: function(html){ //so, if data is retrieved, store it in html
						
							$("#contentloaded").html(html);
							

													
							
							
							
				}, //stop showing loading when the process is complete
				
				complete: function(){ 
				
					var itl = [];
					
					$('#contentloaded img').each(function(index) {

						itl.push($(this).attr("src"));
					  
					
					});

					//alert(itl[0]);
						
					loadheight = $("#contentloaded").outerHeight();
						
						
						
						$('#contentholder').animate({
						   height: loadheight
						 }, 1000, function() {
							  
							  $("#contentloading").fadeTo("fast", 0, function() {
									
								 // $("#contentloading").css("display","none"); 
									$("#contentloaded").fadeTo("slow", 1.0, function() {
										
										//alert(itl[0]);
									annmain = false; 
									
									});
																		
									
								});
							  
							  
						});
					
						
				}
					
					// no real purpose right now but keeping for future
								
				}); //close ajax
				
			
			});
			
		}); // fade out content
	  }
	event.preventDefault();
			
	}); //close click(
	
	var ann = false;
	
	$('#bottomframe a').live("click", function(event) { //start function when menu link is clicked
 		
	if (!ann) {
		
		ann = true;
		var waytoslide;
		var slider;
		var defaultpos; 
		
		$('#bottomframe a').unbind('click');
	
		
		 var content_show = $(this).attr("href"); //retrieve link data so we can send to content_main.php
		 
		 content_show = content_show.replace(webaddress,'');
		 var x = content_show.split("/");
		 
		 
		 var datastring = "";
		 var i=0;
		 for (i=0;i<x.length;i++)
		 {

			 if (i == 1) {
				
				 datastring += "p="+x[i];
				 
			 }
			 else if (i == 2) {
				
				 datastring += "&s="+x[i];
				 
			 }
			 else if (i == 3) {
					
				 datastring += "&id="+x[i];
				 
			 }
			 
			 
		 }
		
		
		
				
		 
		
		 $("#mainframe").fadeTo("slow", 0, function() {
			
			 
			 $("#portload").fadeTo("slow", 1.0, function() {
			 
			 
			 
			 
			 	
				$.ajax({
				type: "get", cache: false, url: "/pages/port_load.php", data: datastring,
				//beforeSend: function(){
					
				//	}
				//	, //show loading just when link is clicked
					
				//complete: function(){ 
				//		}, // no real purpose right now but keeping for future
				success: function(html){ //so, if data is retrieved, store it in html
						
							$("#mainframe").html(html);
							
							
							$('#bottomframe a[rel=previous]').attr("href",$('#mainframe a[rel=prevslideid]').attr("name"));
							$('#bottomframe a[rel=next]').attr("href",$('#mainframe a[rel=nextslideid]').attr("name"));
							
							
											
										
									  
									  
							
							

													
							
							
							
					},
					
				complete: function() {
						
											
						$("#portload").fadeTo("slow", 0, function() {
							 
							$("#mainframe").fadeTo("slow", 1.0, function() {
								 
									 ann = false; 
							 });
									 
						});
				
				}//stop showing loading when the process is complete
								
				}); //close ajax 
				
		 	});
		 
		 });
			
	}
	
	event.preventDefault();
			
	}); //close click(

});



