window.onload = function () {
	
	 var thisposition;
	 $('#nivaroHolder').nivoSlider({
		 
		 
		effect:'fade', //Specify sets like: 'fold,fade,sliceDown'
		slices:15,
		animSpeed:500, //Slide transition speed
		pauseTime:5000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:true, //Next & Prev
		directionNavHide:true, //Only show on hover
		controlNav:true, //1,2,3...
		controlNavThumbs:false, //Use thumbnails for Control Nav
      controlNavThumbsFromRel:true, //Use image rel for thumbs
		controlNavThumbsSearch: '.jpg', //Replace this with...
		controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
		keyboardNav:true, //Use left & right arrows
		pauseOnHover:true, //Stop animation while hovering
		manualAdvance:false, //Force manual transitions
		captionOpacity:0.8, //Universal caption opacity
		beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){} //Triggers after all slides have been shown
		 });
		 
		 $("#navMenuOver").css({
    "left": 0,
	"display":"block",
	"opacity":0});
	
	
	
	if(PageRef=='workPage'){
$('#menu-item-27').addClass('current_page_item');
}
if(PageRef=='blogPage'){
$('#menu-item-30').addClass('current_page_item');
}
	

	
	//hasClass("selected")
	
	
	if ($("#navMenu li").hasClass("current_page_item"))
	{
		// Cufon.replace($(this) , {color: '#fff' });
		// Cufon.refresh();
		//alert(this);

	}


	
jQuery.fn.styleCode = function () {
  return this.each(function () {
    var c = jQuery(this).find(".entry pre");
    c.data("isStyled") != true && c.wrap('<div class="codebg"><div class="codetop"></div></div>').data("isStyled", true)
  })
};

jQuery.fn.collapse = function () {
  return this.each(function () {
    jQuery(this).stop().animate({
      opacity: 0,
      width: 0,
      margin: 0,
      padding: 0
    }, 350)
  })
};

jQuery.fn.expand = function (c) {
  return this.each(function () {
    jQuery(this).stop().animate({
      opacity: 1,
      width: c,
      margin: "0px 15px 30px 0px",
      padding: "0px 0px 20px"
    }, 350)
  })
};


  $("#homeWorkPan li, #thumbnails li").mouseenter(function () {
    $(this).find("img").stop().animate({
      opacity: 0.7
    }, 300).end().find(".viewcasestudy").fadeIn("fast")
  }).mouseleave(function () {
    $(this).find("img").stop().animate({
      opacity: 1
    }, 150).end().find(".viewcasestudy").fadeOut("fast")
  });
  
  
  
  // $(this).parent().parent().find("li a")
   ///// code for main navigation intereaction
   $("#navMenu li").mouseenter(function () {
	   
	 thisposition = $(this).position();
	  
		$("#navMenuOver").css({
    "left": thisposition.left,
	"display":"block",
	"opacity":0
  });
  		 Cufon.replace($(this) , {color: '#fff' });
		 Cufon.refresh();

	   
    $("#navMenuOver").stop().animate({
      opacity: 1
    }, 300)
  }).mouseleave(function () {
	  
	   	Cufon.replace($(this) , { color: '#666' });
		Cufon.refresh();
    $("#navMenuOver").stop().animate({
      opacity: 0
    }, 150)
	
  });

   $("#navMenu .current_page_item").mouseenter(function () {
	   
	 thisposition = $(this).position();
	  
		$("#navMenuOver .current_page_item").css({
    "left": thisposition.left,
	"display":"block",
	"opacity":0
  });
  		 Cufon.replace($(this) , {color: '#fff' });
		 Cufon.refresh();

	   
    $("#navMenuOver .current_page_item").stop().animate({
      opacity: 1
    }, 300)
  }).mouseleave(function () {
	  
	   	Cufon.replace($(this) , { color: '#fff' });
		Cufon.refresh();
    $("#navMenuOver .current_page_item").stop().animate({
      opacity: 0
    }, 150)
	
  });
  
  
  
   $("#navMenu li a").click(function (a)
	{
		//alert($(this));
		//$(this).css("backgroundPosition", "0px  -20px"); 
		setUpPageNav()
		// setUpPageNav($(this).text().replace(" ", "-"))
		

	});

  
  
  /// function to keep nav on for corret page based from info 
  
  function setUpPageNav() 
  {
  window.location.hash = "/";
  //  pageLocation = ($(this).text().replace(" ", "-"))
	//alert(window.location.hash);
	
  }
  
  
     
 
   
   
    $("#contact").mouseleave(function () {
    $("#contactinfo").fadeOut("fast")
  });
  $("#fullscreen").css("opacity", 0);
  $("#profile a").click(function (a) {
    a.preventDefault();
    setUpContactsHiddenMenu()
  });
  $(".contactLnk").click(function (a) {
    a.preventDefault();
    $("html,body").animate({
      scrollTop: 0
    }, 550);
	
	$("#holder").animate({
      marginTop: "300px"
    }, 550);
	
    setUpContactsHiddenMenu()
  });
  $("#fullscreen, .closeprofile").click(function (a) {
    a.preventDefault();
    $("#menu").removeClass("profileactive");
    $("#fullscreen").delay(200).fadeOut("slow");
    $("#hiddenContacts").slideUp(550).find(".closeprofile").fadeOut(200);
    $("#holder").animate({
      marginTop: "0px"
    }, 550)
  });
  
  
   function setUpContactsHiddenMenu() 
  {
    $("#profile a").parent().parent().addClass("profileactive");
    $("#fullscreen").css("display", "block").animate({opacity: 0.7}, 200);
    $("#hiddenContacts").slideDown(550, function () {$(this).find(".closeprofile").fadeIn(200)});
    $("#header").animate({marginTop: "360px"}, 550)
  }
   
   

	//$("#homeWorkPan li").eq(2).addClass("removeMargin");
	//$("#homeWorkPan li").eq(5).addClass("removeMargin");
	  $("#homeWorkPan li").eq(2).animate({marginRight: "0px"})
	   $("#homeWorkPan li").eq(5).animate({marginRight: "0px"})
	     

	   
	   
	   Cufon.replace('#aboutUsPan h2');
	    Cufon.replace('#aboutUsPan h3');
		  Cufon.replace('#homeWorkPan h2');
		   Cufon.replace('#thumbnails li a');
		   	Cufon.replace(' #navMenu li a');
		     Cufon.replace(' #pageHeaderCopy h2, #workCol2 h2, .blogCol2 h2, #feedBackPan h2, .profiledescription li p span, #directionsHolder p ');
			  Cufon.replace(' #filter h2, #workCol2 p strong, #profile h2, #profile h3, .commentsArea p span');
			    Cufon.replace('.blogCol3 p, .blogCol3 p span, .stats p.info, .tags p,  #commentHolder li.col1 p, #commentHolder li.col1 p span, #commentHolder li.col3 p, #commentHolder li.col3 p span');
			
		   
	//// functions below are for work image slider
	  $("#filter a").click(function (a)
	  {
    a.preventDefault();
    $(this).parent().parent().find("li a").removeClass("active").end().end().end().addClass("active");
    window.location.hash = "/" + $(this).text().replace(" ", "-");
    l($(this).text().replace(" ", "-"))
  	});

	
	
	function l(a)
  {
	a = a.toLowerCase();
    a == "everything" ? $("#thumbnails li").expand(m) : $("#thumbnails li").not("." + a).collapse().end().filter("." + a).expand(m)
  }


	
  function n()
  {
    $("#content .tag-post").each(function () {
      var a = $(this).offset().top - 10,
          b = $(this).outerHeight(),
          d = $(window).scrollTop(),
          p = $(this).find(".postInfo").outerHeight(true),
          q = $(this).find(".postInfo").offset().left;
      if (a - d < 0 && a - d > -b && a - d < 10 + p - b) $(this).find(".postInfo").data("fixed", "false").css({
        position: "absolute",
        right: "0px",
        left: "auto",
        bottom: "10px",
        top: "auto"
      });
      else a - d < 0 && a - d > -b ? $(this).find(".postInfo").data("fixed", "true").css({
        position: "fixed",
        left: q + "px",
        bottom: "auto",
        top: "10px"
      }) : $(this).find(".postInfo").data("fixed", "false").css({
        position: "absolute",
        right: "0px",
        left: "auto",
        bottom: "auto",
        top: "0px"
      });
      if ($(this).find(".postInfo").data("fixed") == "true") {
        a = $(this).offset().left + $(this).find(".entry").outerWidth(false) - $(window).scrollLeft();
        $(this).find(".postInfo").css({
          left: a + o + "px"
        });
        console.log($(window).scrollLeft() + " and " + a)
      }
    })
  }
  
    var m = $("#thumbnails li:first").width(),
      e = window.location.hash;
  if (e != "") {
    e = e.split("/");
    l(e[1]);
    $("#filter").find(".active").removeClass("active").end().find(".f" + e[1].toLowerCase()).addClass("active")
  }


		  
		 
		


	
 }



