function nav_overs(id,h,spd){
	$('#'+id+' li').hover(function() {
	$(this).children('.link a').animate({ marginTop: -h }, spd);
	}, function() {
	$(this).children('.link a').animate({ marginTop: -0 }, spd);          
	});	
}


function unit_overs(cls,h,spd){
	$('.'+cls).hover(function() {
 		$(this).children('div').animate({ marginTop: -h }, spd);
 		$(this).children('img').fadeTo('fast', 0.15);
	}, function() {
		$(this).children('div').animate({ marginTop: -0 }, spd);
		$(this).children('img').fadeTo('fast', 1.0);
	});	
}

function centerContent(whgt){
	var hgt = $(window).height();
	var topmarg = Math.ceil((hgt - whgt) / 2);
	if(topmarg <= 0){ topmarg = 0; }
	$('#container').css('margin-top', topmarg );
}

function removeError(){
	$('.txt_inputclient').click(function(){ $(this).removeClass('err'); });
}

function gallery_jump(nm){
	$('#gallery').cycle(nm);
	$('#gallery').cycle('pause');
	$('.pausebtn').hide();
	$('.playbtn').show();
	
}

function fadeRandom(cls){
	var rndnm=Math.floor(Math.random()*$('.'+cls).length);
    setTimeout(function(){$(".unit:eq(0)").fadeIn('fast');}, 3000);
    setTimeout(function(){$(".unit:eq(1)").fadeIn('fast');}, 3100);
    setTimeout(function(){$(".unit:eq(2)").fadeIn('fast');}, 3200);
    setTimeout(function(){$(".unit:eq(3)").fadeIn('fast');}, 3300);
    setTimeout(function(){$(".unit:eq(4)").fadeIn('fast');}, 3400);
    setTimeout(function(){$(".unit:eq(5)").fadeIn('fast');}, 3500);
    setTimeout(function(){$(".unit:eq(6)").fadeIn('fast');}, 3600);
    setTimeout(function(){$(".unit:eq(7)").fadeIn('fast');}, 3700);
    setTimeout(function(){$(".unit:eq(8)").fadeIn('fast');}, 3800);
    
}

function setActive(currSlideElement, nextSlideElement, options, forwardFlag){
	var id = $(this).attr('id');
	$('#thumbnails a').removeClass('active');
	$('#thumbnails a').fadeTo(0,0.70);
	$('#thumbnails a').addClass('transparent');
	$('#thumb_'+id).addClass('active');
	$('#thumb_'+id).removeClass('transparent');
	$('#thumb_'+id).fadeTo(0,1.00);
	
	var slidenum = options.nextSlide;
	if(slidenum === 0){
		$('#gallery').cycle('pause');
		$('.pausebtn').hide();
		$('.playbtn img').attr('src','im/ctrl_replay.png');
		$('.playbtn').show();
		$('.playbtn').click(function(){ $('#gallery').cycle(0); $('.playbtn img').attr('src','im/ctrl_play.png'); resumeGallery(); });
	}
}

function resumeGallery() {
	$('#gallery').cycle('resume');
	$('.playbtn').hide();
	$('.pausebtn').show();
	return false;
}
			
function pauseGallery() {
	$('#gallery').cycle('pause');
	$('.pausebtn').hide();
	$('.playbtn').show();
	return false;
}

function bc_overs(cls){
	$('.'+cls).hover(function() {
	$(this).addClass('over');
	}, function() {
	$(this).removeClass('over');        
	});	
}

function addToPlaylist(id){
		var pars = 'id='+id;
		
		$.ajax({
		   type: "POST",
		   url: "/ajax.add-to-playlist.php",
		   data: pars,
			success: function(msg){
				$('#atp-'+id).hide();
				$('#rfp-'+id).show();
				$('#playlist').removeClass('empty');
				$('#playlist').html(msg);
				
			}
		 });
}

function removeFromPlaylist(id,plid){
		var pars = 'id='+id+'&plid='+plid;
		
		$.ajax({
		   type: "POST",
		   url: "/ajax.remove-from-playlist.php",
		   data: pars,
			success: function(msg){
				$('#rfp-'+id).hide();
				$('#atp-'+id).show();
			}
		 });
}

function ghostImage(id){
	$('#'+id+' img.gall-image').addClass('ghost');
}

function setHeight(){
	var hgt = parseInt($('.gall-image:first').css('height')) + 14;
	$('#homegallery').css('height', hgt+'px');
}

$(document).ready(function(){
	nav_overs('nav','38',0);
	unit_overs('teaser','134',100);

	removeError();
	$('#loclabel').html('Location:');
	$('#etype').val('0');
	$('.bcpanel').click(function(){ window.location = $(this).attr('url'); });
	bc_overs('bcpanel');
	
	$('#fromtheblog').cycle({ 
    	fx:     'fade',
    	timeout: 12000,
    	speed: 'fast',
    	requeueOnImageNotLoaded: true,
    	cleartypeNoBg: true,
    	containerResize: 1,
    	next: '.blog_next',
    	prev: '.blog_prev'
	});
});
