// when the DOM is ready...
function coda3 () {

    var $panels = $('#slider .scrollContainer > div');
	var $panels2 = $('#slider2 .scrollContainer2 > div');
	var $panels3 = $('#slider3 .scrollContainer3 > div');
	var $panels4 = $('#slider4 .scrollContainer4 > div');
    var $container = $('#slider .scrollContainer');
    var $container2 = $('#slider2 .scrollContainer2');
    var $container3 = $('#slider3 .scrollContainer3');
    var $container4 = $('#slider4 .scrollContainer4');

    // if false, we'll float all the panels left and fix the width 
    // of the container
    var horizontal = true;

    // float the panels left if we're going horizontal
    if (horizontal) {
        $panels.css({
            'float' : 'left',
            'position' : 'relative' // IE fix to ensure overflow is hidden
        });
		
        $panels2.css({
            'float' : 'left',
            'position' : 'relative' // IE fix to ensure overflow is hidden
        });
		
        $panels3.css({
            'float' : 'left',
            'position' : 'relative' // IE fix to ensure overflow is hidden
        });
		
        $panels4.css({
            'float' : 'left',
            'position' : 'relative' // IE fix to ensure overflow is hidden
        });
		
        // calculate a new width for the container (so it holds all panels)
        $container.css('width', $panels[0].offsetWidth * $panels.length);
        $container2.css('width', $panels2[0].offsetWidth * $panels2.length);
        $container3.css('width', $panels3[0].offsetWidth * $panels3.length);
        $container4.css('width', $panels4[0].offsetWidth * $panels4.length);
    }
	
	

    // collect the scroll object, at the same time apply the hidden overflow
    // to remove the default scrollbars that will appear
    var $scroll = $('#slider .scroll').css('overflow', 'hidden');
    var $scroll2 = $('#slider2 .scroll2').css('overflow', 'hidden');
    var $scroll3 = $('#slider3 .scroll3').css('overflow', 'hidden');
    var $scroll4 = $('#slider4 .scroll4').css('overflow', 'hidden');

    // apply our left + right buttons
    $scroll
        .before('<img class="scrollButtons left" src="imgsrc/left_s.gif" style="cursor:pointer;" />')
        .after('<img class="scrollButtons right" src="imgsrc/rigth_s.gif" style="cursor:pointer;" />');
		
    $scroll2
        .before('<img class="scrollButtons2 left2" src="imgsrc/left2_s.gif" />')
        .after('<img class="scrollButtons2 right2" src="imgsrc/rigth2_s.gif" />');
		
    $scroll3
        .before('<img class="scrollButtons3 left3" src="imgsrc/left2_s.gif" />')
        .after('<img class="scrollButtons3 right3" src="imgsrc/rigth2_s.gif" />');
		
    $scroll4
        .before('<img class="scrollButtons4 left4" src="imgsrc/left2_s.gif" />')
        .after('<img class="scrollButtons4 right4" src="imgsrc/rigth2_s.gif" />');

    // handle nav selection
    function selectNav() {
        $(this)
            .parents('ul:first')
                .find('a')
                    .removeClass('selected')
                .end()
            .end()
            .addClass('selected');
    }
	
    function selectNav2() {
        $(this)
            .parents('ul:first')
                .find('a')
                    .removeClass('selected')
                .end()
            .end()
            .addClass('selected');
    }
	
    function selectNav3() {
        $(this)
            .parents('ul:first')
                .find('a')
                    .removeClass('selected')
                .end()
            .end()
            .addClass('selected');
    }
	
    function selectNav4() {
        $(this)
            .parents('ul:first')
                .find('a')
                    .removeClass('selected')
                .end()
            .end()
            .addClass('selected');
    }

    $('#slider .navigation').find('a').click(selectNav);
	
    $('#slider2 .navigation2').find('a').click(selectNav2);
	
    $('#slider3 .navigation3').find('a').click(selectNav3);
	
    $('#slider4 .navigation4').find('a').click(selectNav4);

    // go find the navigation link that has this target and select the nav
    function trigger(data) {
        var el = $('#slider .navigation').find('a[href$="' + data.id + '"]').get(0);
        selectNav.call(el);
    }
	
    function trigger2(data2) {
        var el2 = $('#slider2 .navigation2').find('a[href$="' + data2.id2 + '"]').get(0);
        selectNav2.call(el2);
    }	
	
    function trigger3(data3) {
        var el3 = $('#slider3 .navigation3').find('a[href$="' + data3.id3 + '"]').get(0);
        selectNav3.call(el3);
    }	
	
    function trigger4(data4) {
        var el4 = $('#slider4 .navigation4').find('a[href$="' + data4.id4 + '"]').get(0);
        selectNav4.call(el4);
    }	

    if (window.location.hash) {
        trigger({ id : window.location.hash.substr(1) });
        trigger2({ id2 : window.location.hash.substr(1) });
        trigger3({ id3 : window.location.hash.substr(1) });
        trigger4({ id4 : window.location.hash.substr(1) });
    } else {
        $('ul.navigation a:first').click();
        $('ul.navigation2 a:first').click();
        $('ul.navigation3 a:first').click();
        $('ul.navigation4 a:first').click();
    }

    // offset is used to move to *exactly* the right place, since I'm using
    // padding on my example, I need to subtract the amount of padding to
    // the offset.  Try removing this to get a good idea of the effect
    var offset = parseInt((horizontal ? 
        $container.css('paddingTop') : 
        $container.css('paddingLeft')) 
        || 0) * -1;
	
    var offset2 = parseInt((horizontal ? 
        $container2.css('paddingTop') : 
        $container2.css('paddingLeft')) 
        || 0) * -1;
	
    var offset3 = parseInt((horizontal ? 
        $container3.css('paddingTop') : 
        $container3.css('paddingLeft')) 
        || 0) * -1;
	
    var offset4 = parseInt((horizontal ? 
        $container4.css('paddingTop') : 
        $container4.css('paddingLeft')) 
        || 0) * -1;


    var scrollOptions = {
        target: $scroll,
		  // the element that has the overflow

        // can be a selector which will be relative to the target
        items: $panels,

        navigation: '.navigation a',

        // selectors are NOT relative to document, i.e. make sure they're unique
        prev: 'img.left', 
        next: 'img.right',
		

        // allow the scroll effect to run both directions
        axis: 'xy',

        onAfter: trigger,  // our final callback

        offset: offset,

        // duration of the sliding effect
        duration: 500,

        // easing - can be used with the easing plugin: 
        // http://gsgd.co.uk/sandbox/jquery/easing/
        easing: 'swing'
    };
	
	var scrollOptions2 = {
        target: $scroll2,
		  // the element that has the overflow

        // can be a selector which will be relative to the target
		items: $panels2,


        navigation: '.navigation2 a',

        // selectors are NOT relative to document, i.e. make sure they're unique
        prev: 'img.left2', 
        next: 'img.right2',
		

        // allow the scroll effect to run both directions
        axis: 'xy',

        onAfter: trigger2,  // our final callback


		offset: offset2,

        // duration of the sliding effect
        duration: 500,

        // easing - can be used with the easing plugin: 
        // http://gsgd.co.uk/sandbox/jquery/easing/
        easing: 'swing'
    };
	
	var scrollOptions3 = {
        target: $scroll3,
		  // the element that has the overflow

        // can be a selector which will be relative to the target
		items: $panels3,


        navigation: '.navigation3 a',

        // selectors are NOT relative to document, i.e. make sure they're unique
        prev: 'img.left3', 
        next: 'img.right3',
		

        // allow the scroll effect to run both directions
        axis: 'xy',

        onAfter: trigger3,  // our final callback


		offset: offset3,

        // duration of the sliding effect
        duration: 500,

        // easing - can be used with the easing plugin: 
        // http://gsgd.co.uk/sandbox/jquery/easing/
        easing: 'swing'
    };
	
	var scrollOptions4 = {
        target: $scroll4,
		  // the element that has the overflow

        // can be a selector which will be relative to the target
		items: $panels4,


        navigation: '.navigation4 a',

        // selectors are NOT relative to document, i.e. make sure they're unique
        prev: 'img.left4', 
        next: 'img.right4',
		

        // allow the scroll effect to run both directions
        axis: 'xy',

        onAfter: trigger4,  // our final callback


		offset: offset4,

        // duration of the sliding effect
        duration: 500,

        // easing - can be used with the easing plugin: 
        // http://gsgd.co.uk/sandbox/jquery/easing/
        easing: 'swing'
    };
	

    // apply serialScroll to the slider - we chose this plugin because it 
    // supports// the indexed next and previous scroll along with hooking 
    // in to our navigation.
    $('#slider').serialScroll(scrollOptions);
    $('#slider2').serialScroll(scrollOptions2);
	$('#slider3').serialScroll(scrollOptions3);
	$('#slider4').serialScroll(scrollOptions4);

    // now apply localScroll to hook any other arbitrary links to trigger 
    // the effect
    $.localScroll(scrollOptions2);
    //$.localScroll(scrollOptions3);

    // finally, if the URL has a hash, move the slider in to position, 
    // setting the duration to 1 because I don't want it to scroll in the
    // very first page load.  We don't always need this, but it ensures
    // the positioning is absolutely spot on when the pages loads.
    scrollOptions.duration = 1;
    $.localScroll.hash(scrollOptions);

}


function coda2 () {

    var $panels = $('#slider .scrollContainer > div');
	var $panels3 = $('#slider3 .scrollContainer3 > div');
	var $panels4 = $('#slider4 .scrollContainer4 > div');
    var $container = $('#slider .scrollContainer');
    var $container3 = $('#slider3 .scrollContainer3');
    var $container4 = $('#slider4 .scrollContainer4');

    // if false, we'll float all the panels left and fix the width 
    // of the container
    var horizontal = true;

    // float the panels left if we're going horizontal
    if (horizontal) {
        $panels.css({
            'float' : 'left',
            'position' : 'relative' // IE fix to ensure overflow is hidden
        });
		
        $panels3.css({
            'float' : 'left',
            'position' : 'relative' // IE fix to ensure overflow is hidden
        });
		
        $panels4.css({
            'float' : 'left',
            'position' : 'relative' // IE fix to ensure overflow is hidden
        });
		
        // calculate a new width for the container (so it holds all panels)
        $container.css('width', $panels[0].offsetWidth * $panels.length);
        $container3.css('width', $panels3[0].offsetWidth * $panels3.length);
        $container4.css('width', $panels4[0].offsetWidth * $panels4.length);
    }
	
	

    // collect the scroll object, at the same time apply the hidden overflow
    // to remove the default scrollbars that will appear
    var $scroll = $('#slider .scroll').css('overflow', 'hidden');
    var $scroll3 = $('#slider3 .scroll3').css('overflow', 'hidden');
    var $scroll4 = $('#slider4 .scroll4').css('overflow', 'hidden');

    // apply our left + right buttons
    $scroll
        .before('<img class="scrollButtons left" src="imgsrc/left_s.gif" />')
        .after('<img class="scrollButtons right" src="imgsrc/rigth_s.gif" />');
		
    $scroll3
        .before('<img class="scrollButtons3 left3" src="imgsrc/left2_s.gif" />')
        .after('<img class="scrollButtons3 right3" src="imgsrc/rigth2_s.gif" />');
		
    $scroll4
        .before('<img class="scrollButtons4 left4" src="imgsrc/left2_s.gif" />')
        .after('<img class="scrollButtons4 right4" src="imgsrc/rigth2_s.gif" />');

    // handle nav selection
    function selectNav() {
        $(this)
            .parents('ul:first')
                .find('a')
                    .removeClass('selected')
                .end()
            .end()
            .addClass('selected');
    }
	
    function selectNav3() {
        $(this)
            .parents('ul:first')
                .find('a')
                    .removeClass('selected')
                .end()
            .end()
            .addClass('selected');
    }
	
    function selectNav4() {
        $(this)
            .parents('ul:first')
                .find('a')
                    .removeClass('selected')
                .end()
            .end()
            .addClass('selected');
    }

    $('#slider .navigation').find('a').click(selectNav);
	
    $('#slider3 .navigation3').find('a').click(selectNav3);
	
    $('#slider4 .navigation4').find('a').click(selectNav4);

    // go find the navigation link that has this target and select the nav
    function trigger(data) {
        var el = $('#slider .navigation').find('a[href$="' + data.id + '"]').get(0);
        selectNav.call(el);
    }
	
    function trigger3(data3) {
        var el3 = $('#slider3 .navigation3').find('a[href$="' + data3.id3 + '"]').get(0);
        selectNav3.call(el3);
    }	
	
    function trigger4(data4) {
        var el4 = $('#slider4 .navigation4').find('a[href$="' + data4.id4 + '"]').get(0);
        selectNav4.call(el4);
    }	

    if (window.location.hash) {
        trigger({ id : window.location.hash.substr(1) });
        trigger3({ id3 : window.location.hash.substr(1) });
        trigger4({ id4 : window.location.hash.substr(1) });
    } else {
        $('ul.navigation a:first').click();
        $('ul.navigation3 a:first').click();
        $('ul.navigation4 a:first').click();
    }

    // offset is used to move to *exactly* the right place, since I'm using
    // padding on my example, I need to subtract the amount of padding to
    // the offset.  Try removing this to get a good idea of the effect
    var offset = parseInt((horizontal ? 
        $container.css('paddingTop') : 
        $container.css('paddingLeft')) 
        || 0) * -1;
	
    var offset3 = parseInt((horizontal ? 
        $container3.css('paddingTop') : 
        $container3.css('paddingLeft')) 
        || 0) * -1;
	
    var offset4 = parseInt((horizontal ? 
        $container4.css('paddingTop') : 
        $container4.css('paddingLeft')) 
        || 0) * -1;


    var scrollOptions = {
        target: $scroll,
		  // the element that has the overflow

        // can be a selector which will be relative to the target
        items: $panels,

        navigation: '.navigation a',

        // selectors are NOT relative to document, i.e. make sure they're unique
        prev: 'img.left', 
        next: 'img.right',
		

        // allow the scroll effect to run both directions
        axis: 'xy',

        onAfter: trigger,  // our final callback

        offset: offset,

        // duration of the sliding effect
        duration: 500,

        // easing - can be used with the easing plugin: 
        // http://gsgd.co.uk/sandbox/jquery/easing/
        easing: 'swing'
    };
	
	var scrollOptions3 = {
        target: $scroll3,
		  // the element that has the overflow

        // can be a selector which will be relative to the target
		items: $panels3,


        navigation: '.navigation3 a',

        // selectors are NOT relative to document, i.e. make sure they're unique
        prev: 'img.left3', 
        next: 'img.right3',
		

        // allow the scroll effect to run both directions
        axis: 'xy',

        onAfter: trigger3,  // our final callback


		offset: offset3,

        // duration of the sliding effect
        duration: 500,

        // easing - can be used with the easing plugin: 
        // http://gsgd.co.uk/sandbox/jquery/easing/
        easing: 'swing'
    };
	
	var scrollOptions4 = {
        target: $scroll4,
		  // the element that has the overflow

        // can be a selector which will be relative to the target
		items: $panels4,


        navigation: '.navigation4 a',

        // selectors are NOT relative to document, i.e. make sure they're unique
        prev: 'img.left4', 
        next: 'img.right4',
		

        // allow the scroll effect to run both directions
        axis: 'xy',

        onAfter: trigger4,  // our final callback


		offset: offset4,

        // duration of the sliding effect
        duration: 500,

        // easing - can be used with the easing plugin: 
        // http://gsgd.co.uk/sandbox/jquery/easing/
        easing: 'swing'
    };
	

    // apply serialScroll to the slider - we chose this plugin because it 
    // supports// the indexed next and previous scroll along with hooking 
    // in to our navigation.
    $('#slider').serialScroll(scrollOptions);
	$('#slider3').serialScroll(scrollOptions3);
	$('#slider4').serialScroll(scrollOptions4);

    // now apply localScroll to hook any other arbitrary links to trigger 
    // the effect
    $.localScroll(scrollOptions);
    //$.localScroll(scrollOptions3);

    // finally, if the URL has a hash, move the slider in to position, 
    // setting the duration to 1 because I don't want it to scroll in the
    // very first page load.  We don't always need this, but it ensures
    // the positioning is absolutely spot on when the pages loads.
    scrollOptions.duration = 1;
    $.localScroll.hash(scrollOptions);

}
