$(document).ready(function(){
	$(".procure ul li.preview a").click(function(){
		if ($(".bandcamp").css("display") == "block"){
			$(".bandcamp").fadeOut();
		} else {
			$(".bandcamp").fadeIn();
		}
		return false;
	});
	// kill any inactive links
	$(".procure ul li.inactive a").click(function(){
		return false;
	});
	
	if ($("body.home").exists()){
		if ($("#codaphonic-shaboi-split .images").exists()){
			$("#codaphonic-shaboi-split .images .image a:nth-child(2)").css("opacity",0);
			shaboiCycle();
		}
	}
	
	// artist setup
	if ($("body.artist").exists()){
		setupZoom();
		
		var imgCount = $("body.artist .article.first img").length;
		if (imgCount > 1){
			var randStart=Math.floor(Math.random()*imgCount)
			
			$("body.artist .article.first img:not("+randStart+")").css("opacity",0).addClass("inactive");
			$("body.artist .article.first img:eq("+randStart+")").css("opacity",100).addClass("active");
			
			cycleArtistImages();
		}
	}
	
	$("a.email").click(function(){
		var addy = $(this).attr("href");
		var newaddy = addy.replace("_at_","@");
		newaddy = newaddy.replace("_dot_",".");
		window.open("mailto:"+newaddy);
		
		return false;
	});
	
	$(".button").hover(
		function () {
			$(this).addClass("hover");
		  }, 
		  function () {
			$(this).removeClass("hover");
		  }
		);
	
	
	
});

function shaboiCycle(){
	var shaboiTimer = setTimeout(cycleSevenInch,6000);
}
function cycleSevenInch(){
	if ($("#codaphonic-shaboi-split .images .image a:nth-child(2)").css("opacity") == 0){
		$('#codaphonic-shaboi-split .images .image a:nth-child(2)').animate({ opacity: 1 }, 1000, function(){  });
	} else {
		$('#codaphonic-shaboi-split .images .image a:nth-child(2)').animate({ opacity: 0 }, 1000, function(){  });
	}
	shaboiCycle();
}


// looping cycle func
function cycleArtistImages(){
	var artistTimer = setInterval(slideSwitch, 10000);
}
function slideSwitch() {
    var $active = $('.article.first img.active');

    if ( $active.length == 0 ) $active = $('.article.first img:last');

    var $next =  $active.next().length ? $active.next()
        : $('.article.first img:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}





/* jQUERY */
/*	******************************
		PLUGIN - Utility Functions 
		Author: Jack Lukic - KNI (all plugins)
		Notes: Used to extend jQuery functionality and shorten code
	******************************	*/

jQuery.fn.extend({
	// test if el exists
	exists: function() {
		if(this.size() > 0) {
			return true;
		}
		else {
			return false;	
		}
	}
});

