// Tattoo Projects
// Site wide js functions

$(document).ready(function() {
	$(".quickFlip:nth-child(3n)").addClass("lastItem");
	$(".menuBody").hide();
	$("#menuFeed").hide();
	$(".dividerLineTop").hide();
	$(".dividerLineBottom").hide();
	var t = setTimeout(showBody,600);
	function showBody(){
		$(".menuBody").slideDown(1000);
		$(".dividerLineTop").slideToggle(1000);
		$(".dividerLineBottom").slideToggle(1000);
	}
	$(".menuToggle").click(function() {
		$(".menuBody").slideToggle(1000);
		$(".dividerLineTop").stop().slideToggle(1000);
		$(".dividerLineBottom").stop().slideToggle(1000);
		if($('body').scrollTop() > 150) $('body').animate({scrollTop:'150px'}, 600);
		if($('html').scrollTop() > 150) $('html').animate({scrollTop:'150px'}, 600);
	});
	$('#smallAgency').mouseover(function(){
	  var newSrc = $(this).attr("src").replace("header-agencyBlack.jpg", "small-agency-animation.gif");
	  $(this).attr("src", newSrc); 
	});
	$('#smallAgency').mouseout(function(){
	  var newSrc = $(this).attr("src").replace("small-agency-animation.gif", "header-agencyBlack.jpg");
	  $(this).attr("src", newSrc); 
	});

	$("#pressMenu").click(function(e) {
		$("#menuFeed").slideToggle(500);
		e.preventDefault();
	});
});

//rollovers
function findimg(){
	var ia,imgs;
	// loop through all images of the document
	imgs=document.getElementsByTagName('img');
	for(ia=0;ia<imgs.length;ia++){
		// test if the class 'roll' exists
		if(/roll/.test(imgs[ia].className)){
			// add the function roll to the image onmouseover and onmouseout and send
			// the image itself as an object
			preloader(imgs[ia]);
			//imgs[ia].onmouseover=function(){roll(this);};
			//imgs[ia].onmouseout=function(){roll(this);};
		}
	}
}
function roll(o){
	// get the src of the image, and find out the file extension
	var src = o.src;
	var ftype = src.substring(src.lastIndexOf('.'), src.length);
	// check if the src already has an _over and delete it, if that is the case
	if(/_over/.test(src)){
		var newsrc = src.replace('_over','');
	}else{
		// else, add the _over to the src
		var newsrc = src.replace(ftype, '_over'+ftype);
	}
	o.src=newsrc;
}
function preloader(k){
	var imgsrc = k.src;
	var imgName = imgsrc.substring(0, imgsrc.lastIndexOf('.'));
	var imgType = imgsrc.substring(imgsrc.lastIndexOf('.'), imgsrc.length);
	imageObj = new Image();
	imageObj.src=imgName+'_over'+imgType;
} 
$(document).ready(function(){
	findimg();
	$("img.roll")
		.mouseover(function() {
			var src = $(this).attr("src");
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var newsrc = src.replace(ftype, '_over'+ftype);
			$(this).attr("src", newsrc);
		})
		.mouseout(function() {
			var src = $(this).attr("src");
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var newsrc = src.replace('_over','');
			$(this).attr("src", newsrc);
	});
});

