/*************************************
DarkBlueCMS(R) 2010 MASTER WEBSITE
(C)2010 DarkAngel | DarkBlue Consulting
http://www.darkblue.com.ar
	
Si usas este script por favor coloca un link a nuestro sitio. gracias!
if you use this script please place a link to our website. thank you!

**/


/**** Setup ****/
var dbigTimer;
var homePortfolioTimer;
var lastImage;
//-- home

$(document).ready(function() {
    //-- home
    if (document.getElementById("hport") != undefined) {
        lastImage = $('#hport img:last');
        homeLoader();
    };

    //-- search
    if (document.getElementById("search") != undefined) {
        $('form#search').attr({ action: '/cms/search.asp', method: 'post' })
    };

    //-- internal
    if (document.getElementById("dbig") != undefined) {
        dbigSetup();
        dbigTimer = setInterval('dbigRun()', 5000);
    }
})




////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//    Home
//


//-- home loader
function homeLoader() {
    
    $('#hport img:last').ready(function() {
        $('#hport').slideDown().show();
        homePortfolioTimer = setInterval('homePortfolioRun()', 5000);
        homePortfolioSetup();
    });
};

// z-index: 1=back, 5=current, 10=fader, 20=selector
function homePortfolioSetup() {
    $('.hpit').css({ 'opacity': 0.8 });
    $('.hpi:not(:first)').css({ 'position': 'absolute', 'z-index': 1 });
    $('.hpi:first').css({ 'position': 'absolute', 'z-index': 5 }).addClass('sel');
    $('.hpselb').css({ 'background-color': '#ffffff', 'top': 410, 'opacity': 0.5, 'position': 'absolute' });
    $('.hpsel').css({ 'position': 'absolute', 'top': 410 });
    $('.hpsel img')
        .css({ 'opacity': 0.7 })
        .hover(function() { $(this).css('opacity', 1) }, function() { if (!($(this).hasClass('sel'))) { $(this).css('opacity', 0.7) } })
        .click(function() {
            clearInterval(homePortfolioTimer);
            homePortfolioShow($('.hpsel img').index(this));
        });
    $('.hpsel img:first').addClass('sel');

}

function homePortfolioShow(oItem) {
    if ($('.hpi:eq(' + oItem + ')').hasClass('sel')) { return false; };

    //-- switch main
    $('.hpi.sel').css('z-index', 10).removeClass('sel').fadeOut(function() { $(this).css('z-index', 1); });
    $('.hpi:eq(' + oItem + ')').css('z-index', 5).show().addClass('sel');

    //-- switch img
    $('.hpsel img.sel').css('opacity', 0.7).removeClass('sel');
    $('.hpsel img:eq(' + oItem + ')').css('opacity', 1).addClass('sel');

}

function homePortfolioRun() {
    var nIm = $('.hpsel img').index($('.hpsel img.sel').next('img'));
    if (nIm == -1) { nIm = 0 };
    homePortfolioShow(nIm);
}



////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//    Internal
//

// z-index: 1=back, 5=current, 10=fader, 20=selector
function dbigSetup() {
    $('.cig:not(:first)').css({ 'position': 'absolute', 'z-index': 1 });
    $('.cig:first').css({ 'position': 'absolute', 'z-index': 5 }).addClass('sel');
    $('.cigtb').css({ 'background-color': '#ffffff', 'top': $('#dbig').position().top + 305, 'opacity': 0.5, 'position': 'absolute' });
    $('.cigt').css({ 'position': 'absolute', 'top': $('#dbig').position().top + 305 });
    $('.cigt img')
        .css({ 'opacity': 0.7 })
        .hover(function() { $(this).css('opacity', 1) }, function() { if (!($(this).hasClass('sel'))) { $(this).css('opacity', 0.7) } })
        .click(function() {
    clearInterval(dbigTimer);
            dbigShow($('.cigt img').index(this));
        });
        $('.cigt img:first').addClass('sel');

}

function dbigShow(oItem) {
    if ($('.cig:eq(' + oItem + ')').hasClass('sel')) { return false; };

    //-- switch main
    $('.cig.sel').css('z-index', 10).removeClass('sel').fadeOut(function() { $(this).css('z-index', 1); });
    $('.cig:eq(' + oItem + ')').css('z-index', 5).show().addClass('sel');

    //-- switch img
    $('.cigt img.sel').css('opacity', 0.7).removeClass('sel');
    $('.cigt img:eq(' + oItem + ')').css('opacity', 1).addClass('sel');

}

function dbigRun() {
    var nIm = $('.cigt img').index($('.cigt img.sel').next('img'));
    if (nIm == -1) { nIm = 0 };
    dbigShow(nIm);
}


