/* $Id: index.js,v 1.6 2010/08/26 19:03:09 sap Exp $ */

var portfolio_count = 1;
var b2_count = 1;
var b2_items = 1;
var interval_id = false;

$(document).ready(function () {

    // box 1
    var p_items = $('div.top_col div.p_box ').length;

    $('#portfolio_prev').click(function () {
        var $active = $('div.top_col div.active');
        var $next;

            if (portfolio_count > 1)
            {
            $next = $('div.top_col div.p_box ').eq(portfolio_count - 2);
            portfolio_count--;
            }
            else
            {
            $next = $('div.top_col div.p_box ').eq(p_items - 1);
            portfolio_count = p_items;
            }

        $next.addClass('active');
        $active.removeClass('active');
        return false;
    });

    $('#portfolio_next').click(function () {
        var $active = $('div.top_col div.active');
        var $next;

            if (portfolio_count < p_items)
            {
            $next = $('div.top_col div.p_box ').eq(portfolio_count);
            portfolio_count++;
            }
            else
            {
            $next = $('div.top_col div.p_box ').eq(0);
            portfolio_count = 1;
            }

        $next.addClass('active');
        $active.removeClass('active');
        return false;
    });

    // box 2
    b2_items = $('div#b2_wrapper .b2_item').length;
/*
    $('#b2_prev').click(function () {
        
        clearInterval(interval_id);
        var $active = $('div#b2_wrapper .active');
        var $next;

            if (b2_count > 1)
            {
            $next = $('div#b2_wrapper .b2_item').eq(b2_count - 2);
            b2_count--;
            }
            else
            {
            $next = $('div#b2_wrapper .b2_item').eq(b2_items - 1);
            b2_count = b2_items;
            }

        $next.addClass('active');
        $active.removeClass('active');
        return false;
    });

    $('#b2_next').click(function () {

        clearInterval(interval_id);
        var $active = $('div#b2_wrapper .active');
        var $next;

            if (b2_count < b2_items)
            {
            $next = $('div#b2_wrapper .b2_item').eq(b2_count);
            b2_count++;
            }
            else
            {
            $next = $('div#b2_wrapper .b2_item').eq(0);
            b2_count = 1;
            }

        $next.addClass('active');
        $active.removeClass('active');
        return false;
    });
*/
    
    
    
function next_b2_cycle() {
    $('div#b2_wrapper').cycle({ 
        fx: 'scrollLeft',
        speed: 800,
        timeout: 0,
        next: '#b2_next',
        prev: '#b2_prev'
        //pause: 1
    });
}
    
    
$('#clogos_scroll_i').serialScroll({
    //target: '#clogos_scroll_i',
 items:'div.logoitem',
 prev:'div#clogos_prev',
 next:'div#clogos_next',
 offset:-360, //when scrolling to photo, stop 230 before reaching it (from the left)
 //start:3, //as we are centering it, start at the 2nd
 duration: 800,
 force:true,
 stop:true,
 interval:2500,
 //lock:false,
 cycle:false, //don't pull back once you reach the end
 //easing:'easeOutQuart', //use this easing equation for a funny effect
 jump: true, //click on the images to scroll to them
 //onAfter:function( elem ){
         //alert('ss!');   
 //} 
 onBefore:function( e, elem, $pane, $items, pos ){
 /**
 * 'this' is the triggered element
 * e is the event object
 * elem is the element we'll be scrolling to
 * $pane is the element being scrolled
 * $items is the items collection at this moment
 * pos is the position of elem in the collection
 * if it returns false, the event will be ignored
 */
 //those arguments with a $ are jqueryfied, elem isn't.
 
 }
});

    $('#clogos_prev').click(function () {
        $('#clogos_scroll_i').trigger( 'stop' );
    });
    $('#clogos_next').click(function () {
        $('#clogos_scroll_i').trigger( 'stop' );
    });
    $('div.logoitem').click(function () {
        $('#clogos_scroll_i').trigger( 'stop' );
    });


next_b2_cycle();





    
});

//jQuery(function( $ ){ 
//});


/* next_b2: loop images */
function next_b2() {
    
    var $active = $('div#b2_wrapper .active');
    var $next;

        if (b2_count < b2_items)
        {
        $next = $('div#b2_wrapper .b2_item').eq(b2_count);
        b2_count++;
        }
        else
        {
        $next = $('div#b2_wrapper .b2_item').eq(0);
        b2_count = 1;
        }

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

/* init loop images */
//$(function(){ interval_id = setInterval( "next_b2()", 3500 ); });



