// when the DOM is ready...
$(document).ready(function () {
	addScroll("slider",		true);
	addScroll("slider1",	false);

	//*add the random effect*-
	var flowerCount = 4;	// change it as you need

	var flowerElement = document.getElementById("flower");
	if( flowerElement != null ) {
		var r_num = Math.floor((Math.random() * (flowerCount-1)) ) + 1;
		flowerElement.className = "flower_" + r_num;
	}
});

function addScroll(scrollId, horizontal) {
    var $panels = $('#' + scrollId + ' .scrollContainer > div');
	if( document.getElementById(scrollId) == null ) {
		return;
	}

    var $container = $('#' + scrollId + ' .scrollContainer');

    if (horizontal) {
        $panels.css({
            'float' : 'left',
            'position' : 'relative' // IE fix to ensure overflow is hidden
        });
        $container.css('width', $panels[0].offsetWidth * $panels.length);
    }

    var $scroll = $('#' + scrollId + ' .scroll').css('overflow', 'hidden');

    // handle nav selection
    function selectNav() {
        $(this)
            .parents('ul:first')
                .find('a')
                    .removeClass('selected')
                .end()
            .end()
            .addClass('selected');
    }

    $('#' + scrollId + ' .navigation').find('a').click(selectNav);

    // go find the navigation link that has this target and select the nav
    function trigger(data) {
        var el = $('#' + scrollId + ' .navigation').find('a[href$="' + data.id + '"]').get(0);
        selectNav.call(el);
    }

    if (window.location.hash) {
        trigger({ id : window.location.hash.substr(1) });
    } else {
        $('ul.navigation a:first').click();
    }

    var offset = parseInt((horizontal ? 
        $container.css('paddingTop') : 
        $container.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'
    };

    $('#' + scrollId).serialScroll(scrollOptions);
    scrollOptions.duration = 1;
//    $.localScroll(scrollOptions);
//    $.localScroll.hash(scrollOptions);
}