$(document).ready(function(){
$(".jThumbnailScroller").css('overflow', 'visible');
$("#overlay").css('background-color', '#000000');
$("#overlay").css('opacity', '0.6');
$("a.current").live("click", function(e){e.preventDefault();});

$(window).resize(function() { 
  	var center = $(window).width()/2;    
    var left = $("#midbox").width() / 2;
    $("#midbox").css('left', (center - left) + 'px');
  });	

function showRoll(gal) { 
$("#web").hide();
$("#port").hide();
$("#loader").show();
$("#web .jTscrollerContainer .jTscroller").load(gal + ".php", function(){
	var webno = $("#web .jTscrollerContainer .jTscroller").children('a').length;
	var howbig = $("#web .jTscrollerContainer .jTscroller a:first-child").width();
	var nofit = Math.floor($(window).width()/212);
	var spaces = nofit - 1;
	var margins = Math.round(($(window).width() - (nofit * 212))/nofit)/2;
	$("#web .jTscrollerContainer .jTscroller a").css('margin-right', margins + 'px');
	$("#web .jTscrollerContainer .jTscroller a").css('margin-left', margins + 'px');
	$("#web .jTscrollerContainer .jTscroller").css('width', (webno * (212 + (margins *2))) + 'px');
	$("#web .jTscrollerContainer").css('width', (webno * (212 + (margins *2))) + 'px');
	$("#web .jTscrollerContainer .jTscroller a img").each(function(){
       var imglink = 'images/large/' + $(this).attr('src').split('/')[1];
	   var image1 = $('<img />').attr('src', imglink);
	   $("#preload").append(image1);
    });
	
$("#gallery").slideDown(2000, 'easeOutCirc', function(){	
	$("#web .jTscrollerContainer .jTscroller").css('left', '0px');
	$("#web").show();	
	
		$("#web").animate({'left': '0px'}, 1000, 'easeOutCirc', function(){	
			$("#loader").hide();															 
			$("#web").thumbnailScroller({ 
			scrollerType:"hoverPrecise", 
			scrollerOrientation:"horizontal", 
			scrollSpeed:600, 
			scrollEasing:"easeOutCirc", 
			scrollEasingAmount:600, 
			acceleration:2, 
			scrollSpeed:1000, 
			noScrollCenterSpace:10, 
			autoScrolling:0, 
			autoScrollingSpeed:2000, 
			autoScrollingEasing:"easeInOutQuad", 
			autoScrollingDelay:500 
			});																	
			$(".jTscroller a").live("click", function(e){		
			e.preventDefault();		
			$(this).stop().animate({"opacity": ".4"}, 'fast');
			$(".jTscroller a").not(this).stop().animate({"opacity": "1"}, 'fast');
			var currPos = $("#web").offset().left;		
			var boxPos =  $(this).offset().left;
			var center = $(window).width()/2;
			var boxCenter = boxPos + ($(this).width()/2);
			var move = currPos - (boxCenter - center);
			var thisleft = center - ($(this).width()/2);
			var thistop = $(this).offset().top;
			var conlink = $(this).attr('href');
			if ($("#bigbox").length){
					$("#bigbox").html('');
					$("#bigbox").stop().animate({'width': '200px', 'height':'133px', 'left': thisleft + 'px', 'top': '10px', 'opacity':'0'}, 1000, 'easeOutCirc', function(){																															   					$("#bigbox").remove();
					});			 	
					}
			$("#web").stop().animate({'left': move +'px'}, 600, 'easeOutCirc', function(){	
				$("#overlay").show();																										 
			 	$("#bottom").append('<div id="bigbox" style="width:200px; height:133px; border:2px solid #fff; padding:4px; position:absolute; left:'+thisleft+'px; top:10px; display:block;  background-color:#93c717; z-index:40000; opacity:0;"></div>');			
			 	$("#bigbox").stop().animate({'width': '600px', 'height':'600px', 'left': center-306 +'px', 'top': '-300px', 'opacity':'1'}, 400, 'easeOutCirc', function(){
			 	 	$("#bigbox").load(conlink, function(){
						$("#bigbox").css('height', 'auto');
						$("#bigbox").append('<div class="closer">click to close</div>');
			 			$("#bigbox").live("click", function(){
			 				$("#bigbox").html('');
							$("#bigbox").css('height', '600px');
		 					$("#bigbox").stop().animate({'width': '200px', 'height':'133px', 'left': thisleft + 'px', 'top': '10px', 'opacity':'0'}, 1000, 'easeOutCirc', function(){
								$("#bigbox").remove();
								
								$(".jTscroller a").animate({"opacity": "1"}, 'fast');	
								$("#overlay").hide();
							});
						});
			 		});
				});
			});	
	 		
	});
		});

 
 
 
 
	});
});
};


$(window).load(function() {
showRoll('web');
});

function showPort(gal) { 
$("#web").hide();
$("#port").hide();
$("#port").load(gal + ".php", function(){
	var webno = $("#port").children('a').length;
	var howbig = $("#port a:first-child").width();
	var nofit = Math.floor($(window).width()/212);
	var spaces = nofit - 1;
	var margins = Math.round(($(window).width() - (nofit * 212))/nofit)/2;
	$("#port a").css('margin-right', margins + 'px');
	$("#port a").css('margin-left', margins + 'px');
	$("#port").css('width', (webno * (212 + (margins *2))) + 'px');	
	$("#port a img").each(function(){
       var imglink = 'images/large/' + $(this).attr('src').split('/')[1];
	   var image1 = $('<img />').attr('src', imglink);
	   $("#preload").append(image1);
    });
$("#gallery").slideDown(2000, 'easeOutCirc', function(){											
	$("#port").show();	
	var leftSide = ($(window).width() - (webno * (212 + (margins *2) ) ))/2;			
		$("#port").animate({'left': leftSide + 'px'}, 1000, 'easeOutCirc', function(){	
			$("#loader").hide();																		
			$("#port a").live("click", function(e){		
			e.preventDefault();		
			$(this).stop().animate({"opacity": ".4"}, 'fast');
			$("#port a").not(this).stop().animate({"opacity": "1"}, 'fast');
			var currPos = $("#port").offset().left;		
			var boxPos =  $(this).offset().left;
			var center = $(window).width()/2;
			var boxCenter = boxPos + $(this).width()/2;
			var move = currPos - (boxCenter - center);
			var thisleft = center - $(this).width()/2;
			var thistop = $(this).offset().top;
			var conlink = $(this).attr('href');
			if ($("#bigbox").length){
					$("#bigbox").html('');
					$("#bigbox").stop().animate({'width': '200px', 'height':'133px', 'left': thisleft + 'px', 'top': '10px', 'opacity':'0'}, 1000, 'easeOutCirc', function(){
					$("#bigbox").remove();
					});			 	
					}
			$("#port").stop().animate({'left': move +'px'}, 600, 'easeOutCirc', function(){	
				$("#overlay").show();																		 
			 	$("#bottom").append('<div id="bigbox" style="width:200px; height:133px; border:2px solid #fff; padding:4px; position:absolute; left:'+thisleft+'px; top:10px; display:block;  background-color:#93c717; z-index:40000; opacity:0;"></div>');			
			 	$("#bigbox").stop().animate({'width': '600px', 'height':'600px', 'left': center-306 +'px', 'top': '-300px', 'opacity':'1'}, 400, 'easeOutCirc', function(){
			 	 	$("#bigbox").load(conlink, function(){
						$("#bigbox").css('height', 'auto');
						$("#bigbox").append('<div class="closer">click to close</div>');
			 			$("#bigbox").live("click", function(){
			 				$("#bigbox").html('');
							$("#bigbox").css('height', '600px');
		 					$("#bigbox").stop().animate({'width': '200px', 'height':'133px', 'left': thisleft + 'px', 'top': '10px', 'opacity':'0'}, 1000, 'easeOutCirc', function(){
								$("#bigbox").remove();
								$("#port").stop().animate({'left': leftSide + 'px'}, 600, 'easeOutCirc');
								$("#overlay").hide();
								$("#port a").animate({"opacity": "1"}, 'fast');	
								
							});
						});
			 		});
				});
			});	
	 		
	});
		});
	});
});
};

$("#coverlink:not(.current)").live("click", function(e){	
	e.preventDefault();
	$(this).addClass('current');	
	$("#bottommenu").children("a").not(this).removeClass('current');		
	$("#loader").show();	
	$("#web, #port").css('left', '100%');
	$("#gallery").slideUp(800, 'easeOutCirc', function(){														   
		showPort('covers');
		});	
});
$("#weblink:not(.current)").live("click", function(e){
	e.preventDefault();
	$(this).addClass('current');	
	$("#bottommenu").children("a").not(this).removeClass('current');	
	$("#loader").show();	
	$("#web, #port").css('left', '100%');
	$("#gallery").slideUp(800, 'easeOutCirc', function(){													   
		showRoll('web');
		});	
});
$("#logolink:not(.current)").live("click", function(e){	
	e.preventDefault();
	$(this).addClass('current');
	$("#bottommenu").children("a").not(this).removeClass('current');		
	$("#loader").show();	
	$("#web, #port").css('left', '100%');
	$("#gallery").slideUp(800, 'easeOutCirc', function(){												   
		showPort('logos');
		});	
});
$("#medialink:not(.current)").live("click", function(e){	
	e.preventDefault();
	$(this).addClass('current');
	$("#bottommenu").children("a").not(this).removeClass('current');		
	$("#loader").show();
	$("#web, #port").css('left', '100%');
	$("#gallery").slideUp(800, 'easeOutCirc', function(){													   
		showRoll('media');
		});	
});

function showPage(page) {
	
	$("#bottommenu").children().hide();	
	var linkPos =  $("#"+ page).offset().left;
	var center = $(window).width()/2;
	var thisleft = center - $("#"+ page).width()/2;
	var thistop = $("#"+ page).offset().top + $("#"+ page).height();
	var thiswidth = $("#"+ page).width();		
	
	$("#gallery").slideUp(800, 'easeOutCirc', function(){					
		if($("#midbox").length){
		var latestwidth = $("#topmenu a.current").width();		
		var latestleft = $("#topmenu a.current").offset().left;
		var latesttop = $("#topmenu a.current").offset().top + $("#topmenu a.current").height();
		$("#midbox").html('');				
		$("#midbox").stop().animate({'width': latestwidth +'px', 'height':'25px', 'left': latestleft +'px', 'top': latesttop + 'px', 'opacity':'0'}, 1000, 'easeOutCirc', function(){
				$("#midbox").remove();
				$("#top").append('<div id="midbox" style="position:absolute; top:'+ thistop +'px; left:'+ linkPos +'px; width:'+ thiswidth + 'px; height:25px; border:2px solid #fff;  display:block;  background-color:#93c717; z-index:40000; opacity:1.0; "><div class="quickFlip"></div></div>');				
				$("#midbox").stop().animate({'width': '674px', 'height':'500px', 'left': center-337 +'px', 'opacity':'1'}, 1000, 'easeOutCirc', function(){	
					$(".quickFlip").append('<div class="quickFlip1"><div class="flipContent"></div></div><div class="quickFlip2"><div class="flipContent"></div></div>');	
					$(".quickFlip .quickFlip1 .flipContent").load(page + '.php', function(){							
					$('.quickFlip').quickFlip({easing:'easeOutCirc', openSpeed:1600});	
					$(".quickFlip .quickFlip2 .flipContent").load(page + '2.php');		
					});				
					});		
			});			 	
		} else {
			$("#top").append('<div id="midbox" style="position:absolute; top:'+ thistop +'px; left:'+ linkPos +'px; width:'+ thiswidth + 'px; height:25px; border:2px solid #fff;  display:block;  background-color:#93c717; z-index:40000; opacity:1.0; "><div class="quickFlip"></div></div>');					
			$("#midbox").stop().animate({'width': '674px', 'height':'500px', 'left': center-337 +'px', 'opacity':'1'}, 1000, 'easeOutCirc', function(){	
					$(".quickFlip").append('<div class="quickFlip1"><div class="flipContent"></div></div><div class="quickFlip2"><div class="flipContent"></div></div>');	
					$(".quickFlip .quickFlip2 .flipContent").load(page + '2.php');	
					$(".quickFlip .quickFlip1 .flipContent").load(page + '.php', function(){						
					$('.quickFlip').quickFlip({easing:'easeOutCirc', openSpeed:1600});	
					$('.quickFlip2 .flipContent .arrow').live("click", function() {
    					$('.quickFlip').quickFlipper();
						});
					});				
					});		
				}		
	});	
	
};

$("#about:not(.current)").live("click", function(e){		
	e.preventDefault();											 
	$(this).addClass('current');
	$("#topmenu a").not(this).removeClass('current');	
	showPage('about');
	
});

$("#portfolio:not(.current)").live("click", function(e){	
	e.preventDefault();		
	$("#loader").show();
	$("#bottommenu").children().show();	
	$("#web, #port").css('left', '100%');
	
	if($("#midbox").length){
		var latestwidth = $("#topmenu a.current").width();		
		var latestleft = $("#topmenu a.current").offset().left;
		var latesttop = $("#topmenu a.current").offset().top + $("#topmenu a.current").height();
		$("#midbox").html('');				
		$("#midbox").stop().animate({'width': latestwidth +'px', 'height':'25px', 'left': latestleft +'px', 'top': latesttop + 'px', 'opacity':'0'}, 1000, 'easeOutCirc', function(){
		$("#midbox").remove();			
		showRoll('web');
		});			 	
	} else {	
	showRoll('web');
	}
	$(this).addClass('current');
	$("#topmenu a").not(this).removeClass('current');
	$("#bottommenu a").removeClass('current');
	$("#bottommenu a:first").addClass('current');	
});

$("#services:not(.current)").live("click", function(e){		
	e.preventDefault();											 
	$(this).addClass('current');
	$("#topmenu a").not(this).removeClass('current');	
	showPage('services');
	
});
$("#contact:not(.current)").live("click", function(e){		
	e.preventDefault();											 
	$(this).addClass('current');
	$("#topmenu a").not(this).removeClass('current');	
	showPage('contact');
	
});

$("#button1").live("click", function(e){	
	e.preventDefault();
	var data = $("#cont").serialize();
	$.get('sendmail.php', data, function(response) {
		$("#cont").html(response);
		});									 
});
$("#button2").live("click", function(){
	$("#cont").children('input').val('');								 
});
});
