// when the DOM is ready...
var JQ = jQuery.noConflict();		//prevent conflict with other Technology when using [JQ] symbol as special one

//Document Ready is for the Step Navigation only
//It return false if there is Step Navigation Involked
JQ(document).ready(function () {
							 
	//Return
	if(stepNav==0) return;
							 
	JQ('#slider3 .numPage').html((JQ(".navigation a").length));

	var $panels = JQ('#slider3 .scrollContainer > div');
    var $container = JQ('#slider3 .scrollContainer');

    // 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
        });

        // calculate a new width for the container (so it holds all panels)
        $container.css('width', $panels[0].offsetWidth * $panels.length);
    }

    // collect the scroll object, at the same time apply the hidden overflow
    // to remove the default scrollbars that will appear
    var $scroll = JQ('#slider3 .scroll').css('overflow', 'hidden');

    // apply our left + right buttons
   /*
   $scroll
        .before('<img class="scrollButtons left" src="images/scroll_left.png" />')
        .after('<img class="scrollButtons right" src="images/scroll_right.png" />');
	*/


    // handle nav selection
	//YUTH: Comment: to prevent remove focus from Level1 Navigation
    /*function selectNav() {			
		alert("sdfdsf");
        JQ(this)
            .parents('#slider3 .navigation ul:first')
                .find('a')
                    .removeClass('selected')
                .end()
            .end()
            .addClass('selected');
    }
	*/


    JQ('#slider3 .navigation').find('a').click(selectNav);

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

    if (window.location.hash) {
        trigger( { id : window.location.hash.substr(1) } );	
    } else {
        JQ('#slider3 ul.navigation 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 scrollOptions = {
        target: $scroll, // the element that has the overflow

        // can be a selector which will be relative to the target
        items: $panels,

        navigation: '#slider3 .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: 100,

        // 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.
    JQ('#slider3').serialScroll(scrollOptions);

    // now apply localScroll to hook any other arbitrary links to trigger 
    // the effect
    JQ.localScroll(scrollOptions);

    // 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;
    JQ.localScroll.hash(scrollOptions);
	
});

//Function setScroll
function setScroll(id,skipArrow){

	//Skip if id = 3
	if(id==skipArrow) return;

    var $panels = JQ('#slider'+id+' .scrollContainer > div');
    var $container = JQ('#slider'+id+' .scrollContainer');
    var horizontal = true;
   
   if (horizontal) {
        $panels.css({
            'float' : 'left',
			'clear' : 'both'
			,'position' : 'absolute' // IE fix to ensure overflow is hidden
        });        
        $container.css('width', $panels[0].offsetWidth * $panels.length);
    }
   
    var JQscroll = JQ('#slider'+id+' .scroll').css('overflow', 'hidden');
	
	JQ('#slider'+id+' .navigation').find('a').click(selectNav);
	
    if (window.location.hash) {
        trigger( { id : window.location.hash.substr(1) } );		
    } else {					
        JQ('#slider'+id+' ul.navigation a:first').click();
    }
    
    var offset = parseInt((horizontal ? 
        $container.css('paddingTop') : 
        $container.css('paddingLeft')) 
        || 0) * -1;


    var scrollOptions2 = {
        target: JQscroll, // the element that has the overflow
        items: $panels,
        navigation: '#slider'+id+' .navigation a',
        prev: 'img.left'+id, 
        next: 'img.right'+id,
        axis: 'xy',
        onAfter: trigger, // our final callback
        offset: offset,
        duration: 500,
        easing: 'swing'
    };
	
    JQ('#slider'+id).serialScroll(scrollOptions2);	
	
    //JQ.localScroll(scrollOptions2);
	
    scrollOptions2.duration = 1;
    JQ.localScroll.hash(scrollOptions2);	
	
}

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




// go find the navigation link that has this target and select the nav
function trigger(data) {

	JQ('#slider'+data.title+' .pageNum').html(data.className);
	var el = JQ('#slider'+data.title+' .navigation').find('a[href$="' + data.className + '"]').get(0);	
	selectNav.call(el);
}

function addPages(slidID,skipArrow){
		
	if(slidID == skipArrow)	return;
	
	var scollWidth = JQ('#slider'+slidID+' .scroll').height()+ 50;
	
	
	//alert(scollWidth );
	var k=1;
	var str = "";
	for (var i=scollWidth ; i<=JQ('#slider'+slidID+' .1').height() ; i+=scollWidth)
	{
		k++;
		//alert(k);
		str += '<div style=" position: absolute; top:'+i+'px; left:0px;" title="'+slidID+'" class="'+k+'" ></div>';
		
	}
	
	//alert(str);
	JQ('#slider'+slidID+' .scrollContainer').html(JQ('#slider'+slidID+' .scrollContainer').html()+str);
	JQ('#slider'+slidID+' .numPage').html(k);
	
}



//subNavigationClick
function changeSubNavigation(obj){
	
	var idSlider = obj.id.substr(obj.id.length-7, obj.id.length);
	var clsSlider = idSlider.substr(0,idSlider.length-1);	
	//alert(idSlider);
	//Hide all block
	JQ('body')
		.find('div.'+clsSlider)
			.css({'display':'none'})
		.end();

	//Show the block selected
	JQ('#'+idSlider).css({'display':'block'});
	
	//SubNavigation sets to selected
	
	
	
	JQ(obj)
		.parents('ul:first')
			.find('a')
				.removeClass('selected')
			.end()
		.end()
		.addClass('selected');
		
	return false;
}

//subNavigationClick
function startSubNavigation(clsSlider,idSlider,idMySlider){

		
	//Hide all block
	JQ('body')
		.find('div.'+clsSlider)
			.css({'display':'none'})
		.end();

	//Show the block selected
	JQ('#'+idSlider).css({'display':'block'});
	
	//SubNavigation sets to selected	
	JQ('#'+idMySlider).attr("class","selected");	
				
}
