/************************/
// sifr menus etc
/************************/
$(function () {
	
	$('#head-container .right ul li a').prepend('<span></span>');
	$('#head-container .right').droppy();
	$('.index-page h1, .index-page h2').sifr({
		path : '/_flash/sifr/',
		font : 'sifr',
		save : true,
		embedOptions : { 
			wmode : 'transparent'
		}
	});
	
});


// head menu
$('#head-container .left li:last-child').mouseover(function () {
	$('#head-container .left li:first-child').css('background-position', '-1941px 0');
}).mouseout(function () {
	$('#head-container .left li:first-child').css('background-position', '-294px 0');
});
$('#head-container .right li a#artists-nav').mouseover(function () {
	$('#head-container .left li:first-child').css('background-position', '-1900px 0');
}).mouseout(function () {
	$('#head-container .left li:first-child').css('background-position', '-294px 0');
});


/************************/
// captcha
/************************/
function randImg() {
    
    $('#abc').html('Loading...');
    $.ajax({
        url : '/vision/randimg/img/',
        success : function (img) {
            $('#abc').html(img); 
            return true;
        }
    });
};


/************************/
// adjust footer height
/************************/
function footerHeight() {
    
    var footerHTML, heightCalc;
    
    footerHTML = document.getElementById('vision-foot');
    heightCalc = document.documentElement.clientHeight - (footerHTML.offsetTop + 54);
    
    //alert(heightCalc);
    
    if (heightCalc > 45) {
        footerHTML.style.height = heightCalc + 'px';
    } else {
        footerHTML.style.height = 'auto';
    }
    
};


$(document).ready(function () {
    
    if ($('#abc').length !== -1 && $('#cd').length > 0) {
        randImg();
    }
    
    if ($('#vision-foot').length > 0) {
        footerHeight();
        $(window).resize(function () {
            footerHeight();
        });
    }
    
    return false;
});


/************************/
// smooth status
/************************/
function swapStatus(status) {
    
    if ($('#status').css('display') === 'none') {
        
        $('#status').html('&nbsp;').slideDown(500, function () {
            $('#status').html(status);
            $('#status *').fadeIn(200);
        });
        
    } else if ($('#status *').html() !== status.replace(/<\S[^>]*>/g, '')) {
        
        $('#status *').fadeOut(200, function () {
            $('#status').html(status);
            $('#status *').fadeIn(200);
        });
        
    }
};


/************************/
// submit comments form
/************************/
$('#comments-form').submit(function () {

    $('#status').html('Adding your comment...').slideDown('slow');
    $('#comment').val(FCKeditorAPI.GetInstance('comment').GetHTML());
    $.ajax({
        url : $('#comments-form').attr('href'), 
        type : 'POST', 
        data : $('#comments-form').serialize(), 
        success : function (status) {
            $('#status').html(status);
        }
    });
    
    return false;
});





// gallerific for artist's page
if ((document.getElementById('main-container').className.indexOf('artists-list-page') !== -1 || document.getElementById('main-container').className.indexOf('index-page') !== -1) &&
    window.location.href.indexOf('edit_page') === -1 && window.location.href.indexOf('add_page') === -1) {
    
    $(document).ready(function () {
		
		// add the id an classnames required for the rotator, is easier to do it here than to rely on ppl doing it through the editor
		$('#thumbs-adv ul').addClass('thumbs noscript');
		$('#thumbs-adv ul li a').addClass('thumb');
		
        var galleryAdv = $('#gallery-adv').galleriffic('#thumbs-adv', {
            delay:                  7000,
            numThumbs:              50,
            preloadAhead:           20,
            imageContainerSel:      '#slideshow-adv',
            controlsContainerSel:   '#controls-adv',
            autoStart:              true,
            onTransitionOut:        function (callback) {
                $('#slideshow-adv').fadeOut(2000, callback);
            },
            onTransitionIn:         function () {
                $('#slideshow-adv').fadeIn(2000, function() {$('#gallery-adv').css('background', 'none');});
            }
        });
    });
    
}