/* ---------------------------------------------------------------------
JavaScript for aden + anais
FileName: common.js
--------------------------------------------------------------------- */

// *** png fix
$(function(){
	$(document).pngFix();
});

// *** lightbox
$(function() {
    $('#photo_l a').lightBox();
});

// *** swap and preload images
function imgChange(imgObj){
	var imgSrc = imgObj.src;
	var imgStatus = imgSrc.indexOf("_on") != -1;
	if(!imgStatus){
		var P = imgSrc.lastIndexOf(".");
		imgSrc = imgSrc.substr(0, P) + '_on' + imgSrc.substring(P);
	} else {
		imgSrc = imgSrc.replace('_on', '');
	}
	imgObj.src = imgSrc;
}

$(function(){
	$('.swapImg').hover(function(){imgChange(this);}, function(){imgChange(this);});
	var swapObj = $('.swapImg');
	imgPreLoad(swapObj);
});

function imgPreLoad(swapObj){
	preLoadImg = new Array();
	for(i = 0; i < swapObj.length; i++){
		var imgSrc = swapObj[i].src;
		var P = imgSrc.lastIndexOf(".");
		imgSrc = imgSrc.substr(0, P) + '_on' + imgSrc.substring(P);
		preLoadImg[i] = new Image();
		preLoadImg[i].src = imgSrc;
	}
}

// *** pagetop scroll
$(document).ready(function(){
	$('.totop').click(function(){
		$('html,body').animate({scrollTop: 0}, 600, 'easeOutCubic');
		return false;
	});
});

