﻿var scrollWrapW,myScroll;
var rollDirection = 0; //0 left 1 right
var speed = 3600;

function __scrollInit(){
	    $('.scrollable ul .orange').each(function(){
	        var index=$('.scrollable ul .orange').index($(this));
		    if(index< 5)
		    {	
               $(this).removeClass('orange2');
		    }else{
               $(this).addClass('orange2');
		    };
	    });
	    $('.scrollable ul div').each(function(){
	        var index=$('.scrollable ul div').index($(this));
		    if(index< 5)
		    {	
		          $(this).addClass("div");						
		          $(this).css("display","block");
		                  if($.browser.mozilla){ 
			                    if($('img',this).height()<50){
				                    $('img',this).css("margin-top",12);}else{
				                    $('img',this).css("margin-top",0); }
		                    }
		    }else{
		      $(this).removeClass("div");
		      $(this).css("display","none");
		    };
	    });
	    $('.scrollable').css("display","block");
}

function __scrollBox(){
 if (rollDirection == 0){
	 scrollWrapW = -($('.scrollable ul').eq(0).outerWidth(true) + $('.scrollable ul').eq(1).outerWidth(true)) + 'px';
	 $('.scrollable').animate({left:scrollWrapW}, {
	   duration:200,
	   complete:function(){
		 $('.scrollable').append($('.scrollable ul:first')).append($('.scrollable ul:first'));
		 $('.scrollable').css("left","0");
            __scrollInit();
		}
	  });
 }else{
	var last = $('.scrollable ul').length - 1;
	var last2 = $('.scrollable ul').length - 2;
	scrollWrapW = -($('.scrollable ul').eq(last).outerWidth(true) + $('.scrollable ul').eq(last2).outerWidth(true)) + 'px';
	$('.scrollable').animate({left:0}, {
	   duration:200,
	   complete:function(){
		   $('.scrollable').prepend($('.scrollable ul:last')).prepend($('.scrollable ul:last'));
		   $('.scrollable').css("left",scrollWrapW);
		}
	  });
 }
}

$(document).ready(function(){
    /* roll control */
    __scrollInit();
        myScroll = setInterval(__scrollBox,speed);
        $('.scrollable').hover( function(){ clearInterval(myScroll); }, function(){ myScroll = setInterval(__scrollBox,speed); });        
        var clipboardStr = $('#scrollScript').attr('clip');
        var clipboard = clipboardStr.split(',');
        var clen = clipboard.length;
        var str="",id,code,name;
        for(var i=0;i < clen;i++){
            name = "scroll_clip_button_" + i;id   = "#" + name;code = (clipboard[i]==null)?"":clipboard[i];
            str += "var s = new ZeroClipboard.Client();s.setText('');s.setHandCursor(true);s.addEventListener('mouseOver',function(client) { clearInterval(myScroll);} );s.addEventListener('mouseDown',function(client) { client.setText('" + code + "');} );s.addEventListener('complete',function(client) { window.open($('" + id + "').get(0).href); });s.glue('" + name + "');s.setCSSEffects(false);";
	    };eval(str);	    
});