/*
	EPIC MENU OF AWEEEEESOME
[0] Peaker Slider Down
[1] Peaker Toogle Slider
[2] Banner Toration
[3] Navigation of Main Content
[4] Expert-slide funky carosel.
[4.1] Expert-slide: Toggle
[4.2] Expert-slide: Back Buttons
[5] Over toggle functions

		====================
		
*/
$(document).ready(function(){
// [Functions]
        $(window).scroll(function() {
            if ($(window).scrollTop() >= 15*11) {
                $("#fixed-project-header").show();
                $("#projects-nav, article hgroup").css("visibility", "hidden");
            } else {
                $("#fixed-project-header").hide();
                $("#projects-nav, article hgroup").css("visibility", "visible");
            }
        });

// [Switch Toggle]
function swapnavlinks(thelink){
	var linkage = "#" + thelink + " a";
	$("#nav ul li a").removeClass("navactive");
	$("#nav ul li a").addClass("nonactive");
	$(linkage).removeClass("nonactive")
	$(linkage).addClass("navactive");
}

function siteload(){
var mainbg = "#121212 url('er_bg.png') no-repeat center top"; /*url('111.jpg')*/
var expertbg = "#121212 url('expertbg.png') no-repeat center top";
var portbg = "#121212 url('pattern_40.gif')";
var tutbg = "#121212";
var blogbg = "#121212";
var contactbg = "#121212";
var aboutchrisbg = "#121212";
function checkbodyheight(){
	
}

$(window).scroll(function(){
	var h = $('body').height();
	var y = $(window).scrollTop();
	
	if( y > 100 ){
		$(".tip").fadeIn("slow");
	} else {
		$('.tip').fadeOut('slow');
	}
})

function moocab(buttonfind1){
	    var designergroup = buttonfind1;
		if ($(designergroup).is(':visible')){
				}else{	
				$(designergroup).animate({"margin-left": "24px"}, { queue: false, duration: 1000 } );
				$(designergroup).fadeIn(1000).siblings().hide();
				$(designergroup).siblings().animate({"margin-left": "0px"}, { queue: false, duration: 1000 } );
				}
}
function moocab1(hawt){
var getId = hawt;
var cellid = "failure";
if(getId[0]=="#about"){cellid = "#dl1";}
if(getId[0]=="#expertise"){cellid = "#dl2";}
if(getId[0]=="#portfolio"){cellid = "#dl3";}
if(getId[0]=="#tuts"){cellid = "#dl4";}
if(getId[0]=="#blogger"){cellid = "#dl5";}
if(getId[0]=="#contat"){cellid = "#dl6";}
if(getId[0]=="#aboutchris"){cellid = "#dl7";}
	
		if ($(cellid).is(':visible')){
		}else{
	
				var divHeight = $(cellid + " > div:first").height();
				$("#midseg").animate({ height: divHeight},750);
				$("#midseg").css("background","#FFF");
				$("#midbottabs").fadeOut("slow").hide();
				$("#portcontentpreload").show();
				$("#portcontent").hide();
				$(cellid).fadeIn(1000).siblings().hide();
		}
			if(cellid=="#dl1"){
				$("#midbottabs").fadeIn(1500).show();	
				$("#midseg").css("background",mainbg);
				swapnavlinks("l1");
			}
		   if(cellid=="#dl2"){
				$("#midseg").css("background",expertbg);
				swapnavlinks("l2");
			}
		   if(cellid=="#dl3"){
				$("#midseg").css("background",portbg);
				swapnavlinks("l3");
				setTimeout(function(){
					$("#portcontentpreload").hide();
					$("#portcontent").show();
				},1500)
			}
		   if(cellid=="#dl4"){
				$("#midseg").css("background",tutbg);
				swapnavlinks("l4");
			}
		   if(cellid=="#dl5"){
				$("#midseg").css("background",blogbg);
				swapnavlinks("l5");
			}
		   if(cellid=="#dl6"){
				$("#midseg").css("background",contactbg);
				swapnavlinks("l6");
			}
		   if(cellid=="#dl7"){
				$("#midseg").css("background",aboutchrisbg);
					$("#nav ul li a").removeClass("navactive");
					$("#nav ul li a").addClass("nonactive");
			}
		var movetox = "."+getId[1];
		setTimeout(function(){
		$.scrollTo( $(movetox), 1000);
		},500);
cellid= "failure";	
}
$(".linker").click(function(){
 var linkholder = $(this).attr('href').split('-');
	setTimeout(function(){
	 moocab1(linkholder);
	 },250);
})	

// [0] Peaker Slider Down
		$("#peaker").click(function(){
			$("#splash").slideToggle("slow");
		});
// [1] Peaker Slide Up
		 $("#splash").click(function(){
			$("#splash").slideToggle("slow");
		  });

// [2] Banner Rotation		  
	$(".paging").show();
		$(".paging a:first").addClass("active");

		var imageWidth = $(".window").width();
		var imageSum = $(".image_reel li").size();
		var imageReelWidth = imageWidth * imageSum;

		$(".image_reel").css({'width' : imageReelWidth});

		rotate = function(){
			var triggerID = $active.attr("rel") - 1; 
			var image_reelPosition = triggerID * imageWidth; 
			$(".paging a").removeClass('active');
			$active.addClass('active'); 
				$(".image_reel").animate({left: -image_reelPosition}, 500 );
				
		}; 

		rotateSwitch = function(){
			play = setInterval(function(){ 
				$active = $('.paging a.active').next(); 
					if ( $active.length === 0) { 
						$active = $('.paging a:first');						
				}
				rotate();}, 4000); 
		};

rotateSwitch();  //Run the rotation.

		$(".image_reel li").hover(function() {		
			clearInterval(play);
			handon = setTimeout(function(){rotateSwitch()},10000)}, function() {
				clearTimeout(handon);
				clearInterval(play);
				rotateSwitch();
		});	

		
		function tabshoverfx (tabname,tabcolor){
			clearInterval(play);
			$(tabname).css("background",tabcolor);
			$(tabname).css("cursor","hand");
		}


		$(".paging a").click(function() {
			$active = $(this);
			clearInterval(play);
			rotate(); 
			rotateSwitch();
			return false;
		});
		
			$("#left-121").hover(function() {
				tabshoverfx("#left-121","url('rightarrowhover1.png')");
			}, function() {
				tabshoverfx("#left-121","url('rightarrow.png')");
				rotate();
				rotateSwitch();
			});
		
			$("#right-121").hover(function() {
				tabshoverfx("#right-121","url('leftarrowhover1.png')");
			}, function() {
				tabshoverfx("#right-121","url('leftarrow.png')");
				rotate();
				rotateSwitch();
			});
			
$("#left-121").click(function() {
	$active = $('.paging a.active').next(); 
		if ( $active.length === 0) { 
			$active = $('.paging a:first');						
	}
	clearInterval(play);
	rotate();
	rotateSwitch();
});

$("#right-121").click(function() {
	$active = $('.paging a.active').prev(); 
		if ( $active.length == 0) { 
		$active = $('.paging a:last');						
	}
	clearInterval(play);
	rotate();
	rotateSwitch();
}); 

  
// [3] Navigation of main content. 
$("#portmenu-list li").click(
   function() {
	 var theId = "#d" + $(this).attr('id');
		if ($(theId).is(':visible')){}else{
		$(theId).fadeIn(1000).siblings().hide();
		}
   });  

   $("#navlinks li").click(
   function() {
      var theId = "#d" + $(this).attr('id');
		if ($(theId).is(':visible')){	

				}else{
				var divHeight = $(theId + " > div:first").height();
				$("#midseg").animate({ height: divHeight},750);
				$("#midseg").css("background","#FFF");
				$("#midbottabs").fadeOut("slow").hide();
				$(theId).fadeIn(1000).siblings().hide();
				$("#portcontentpreload").show();
				$("#portcontent").hide();
				}
		   if($(this).attr('id')=="l1"){
				$("#midbottabs").fadeIn(1500).show();	
				$("#midseg").css("background",mainbg);
					swapnavlinks($(this).attr('id'));
			}
		   if($(this).attr('id')=="l2"){
				$("#midseg").css("background",expertbg);
					swapnavlinks($(this).attr('id'));
			}
		   if($(this).attr('id')=="l3"){
				$("#midseg").css("background",portbg);
				swapnavlinks($(this).attr('id'));
				setTimeout(function(){
					$("#portcontentpreload").hide();
					$("#portcontent").show();
				},1500);
			}
		   if($(this).attr('id')=="l4"){
				$("#midseg").css("background",tutbg);
				swapnavlinks($(this).attr('id'));
			}
		   if($(this).attr('id')=="l5"){
				$("#midseg").css("background",blogbg);
				swapnavlinks($(this).attr('id'));
			}
		   if($(this).attr('id')=="l6"){
				$("#midseg").css("background",blogbg);
				swapnavlinks($(this).attr('id'));
			}
        }
    )
	

// [4] Expert-slide funky carosel
var deg=0;
	var dif=-3;
	var arr = $('.btn');
	var len = arr.length;
	var centerX = $('#rp0').width()/2 - 50;
	var centerY = $('#rp0').height()/2 - 85;

	arr.css('position','absolute');

	setInterval(function(){
		if(Math.abs(dif)<0.5) return false;
		deg+=dif;
		$.each(arr,function(i){
			var eSin = Math.sin(((360/len)*i+deg)*Math.PI/180);
			var eCos = Math.cos(((360/len)*i+deg)*Math.PI/180);
			$(this).css({
				top:centerY+25*eSin,
				left:centerX+90*eCos,
				opacity:0.8+eSin*0.2,
				zIndex:Math.round(80+eSin*20)
			});
		})
	},40);

	var over=false;
	$("#rp0").mousemove(function(e){

		if(!this.leftOffset){
			this.leftOffset = $(this).offset().left;
			this.width = $(this).width();
		}
		if(over) dif=0;
		else
			dif = -5+(10*((e.pageX-this.leftOffset)/this.width));

	});

	$(".bcontent").hover(
		function(){over=true;dif=0;},
		function(){over=false;}
	);
  

// [4.1] Expert-slide, toggle 
$("#carosel li").click(
   function() {
      var theId3 = "#r" + $(this).attr('id');
	  var theId5 = "#q" + $(this).attr('id');
		if ($(theId3).is(':visible')){	
				}else{			
				$(theId3).fadeIn(1000).siblings().hide();
				$(theId5).fadeIn(1000).siblings().hide();
				}
})

// [4.2] Expert-slide: Back Buttons 
$("#des-back,#coder-back,#art-back,#db-back,#tech-back").click(
   function() {
			moocab("#r" + $(this).attr('class'));
			moocab("#q" + $(this).attr('class'));
			$("#stage-display").css("background","transparent");	
})

$("#des-back,#coder-back,#art-back,#db-back,#tech-back").hover(
	function(){
		var getthisone = "#" + $(this).attr('id');
		  $(getthisone).animate({"margin-left": "10px"}, "fast");
		  $(getthisone).css("font-size","15px");
			$(getthisone).css("font-weight","bold");
},function(){
			var getthisone = "#" +  $(this).attr('id');
  $(getthisone).animate({"margin-left": "0px"}, "fast");
  $(getthisone).css("font-size","12px");
    $(getthisone).css("font-weight","normal");
})
// []
$("#carosel li").hover(function(){
	var theId17 = "#" + $(this).attr('id') + " img";
	  $(theId17).animate({"width": "64px"}, "fast");
},function(){
		var theId17 = "#" + $(this).attr('id') + " img";
	  $(theId17).animate({"width": "32px"}, "fast");
})

// [4.4] Expert-slide: Link Hover Effects 
$("#designer-list li,#coders-list li,#artist-list li,#db-list li,#tech-list li").hover(
function(){
	var getthisone = "#" + $(this).attr('id');
  $(getthisone).animate({"margin-left": "10px"}, "fast");
  $(getthisone).css("background","red");
  $(getthisone).css("font-size","12px");
    $(getthisone).css("font-weight","bold");
},function(){
	var getthisone = "#" +  $(this).attr('id');
  $(getthisone).animate({"margin-left": "0px"}, "fast");
    $(getthisone).css("background","transparent");
  $(getthisone).css("font-size","12px");
    $(getthisone).css("font-weight","normal");
})

// [5] Overall toggles 
$("#designer-list li").click(function(){
		moocab("#design-list-topics-" + $(this).attr('id'));
})
$("#coders-list li").click(function(){
		moocab("#coder-list-topics-" + $(this).attr('id'));
})

$("#artist-list li").click(function(){
		moocab("#artist-list-topics-" + $(this).attr('id'));
})
$("#db-list li").click(function(){
		moocab("#db-list-topics-" + $(this).attr('id'));
})
$("#tech-list li").click(function(){
		moocab("#tech-list-topics-" + $(this).attr('id'));
})
$("#expert li").click(function() {
	moocab("#s" + $(this).attr('id'));
})



// [7] Linker test


$(".tip").click(function(){
 $.scrollTo( $('body'), 1000);
})

var auto_refresh = setInterval(function (){
$('#peaker').load('timekeep.php').fadeIn("slow");
}, 1000);


// [Code Dump]
/*
$("#designer-list li").click(
   function() {
      var designergroup = "#design-list-topics-" + $(this).attr('id');

		if ($(designergroup).is(':visible')){	
				}else{			

				$(designergroup).fadeIn(1000).siblings().hide();
				}
        }
    )

*/  


//Check URL
function gethasanddisplay(swapid,bgimage){
	var useID = swapid;
	$(useID).fadeIn(1000).siblings().hide();
	var divHeight = $(useID + " > div:first").height();
	$("#midseg").animate({ height: divHeight + 70},750);
	$("#midseg").css("background",bgimage);
	$("#midbottabs").fadeOut("slow").hide();
	$("#portcontentpreload").show();
	$("#portcontent").hide();
}
	if(location.hash=="#experter"){gethasanddisplay("#dl2",expertbg);
									swapnavlinks("l2");}
	if(location.hash=="#portfolio"){gethasanddisplay("#dl3",portbg);
									swapnavlinks("l3");
				setTimeout(function(){
					$("#portcontentpreload").hide();
					$("#portcontent").show();
				},1500);
				}
	if(location.hash=="#tuts"){gethasanddisplay("#dl4",tutbg);
									swapnavlinks("l4");}
	if(location.hash=="#blogger"){gethasanddisplay("#dl5",blogbg);
									swapnavlinks("l5");}
	if(location.hash=="#contacter"){gethasanddisplay("#dl6",contactbg);
									swapnavlinks("l6");}
	if(location.hash=="#aboutchris"){gethasanddisplay("#dl7",aboutchrisbg);
									swapnavlinks("l7");}
}
siteload();



}); //End Document 
