
function createGallery(){
    
    idx = 0;
    slidesN = $(".hpSlide").size();
    
    $("#main_element").css({
        "position":"relative",
        "width":"955px",
        "height":"266px",
        "overflow":"hidden"
        
        
    })
    $(".hpSlide").css({
        "position":"absolute",
        "opacity":"0",
        "width":"955px",
        "display":"block"
    });
    
    $(".hpSlide").find(".sliderMask").css({
        "position":"absolute",
        "left":"0",
        "top":"0"
    });
    var _color = $(".hpSlide").css("color");
    $(".slideTxt").css({
        "color":_color,
        "position":"absolute",
        "right":"20px",
        "top":"0",
        "width":"350px",
        "padding-top":"100px",
        "line-height":"24px"
    });
    
    initAnim();
}

function initAnim(){
    
    var _slide  = $(".hpSlide").eq(idx);
    var _ck =typeof currentSlide;
    if(_ck!="undefined"){
        currentSlide.animate({
            opacity:0
        },400);
        currentSlide.find(".slideTxt").animate({
            "top":"-255px"
        },400,function(){
            $(this).css({
                "top":"0"
            })
        })
    }
    currentSlide = _slide;
    currentSlide.animate({
        opacity:1
    },600);
    
    currentSlide.find(".slideTxt").css({
        "top":"255px"
    })
    currentSlide.find(".slideTxt").animate({
        "top":"0px"
    },600);
    idx = (idx+1)%slidesN;
    
    setTimeout(initAnim,9000);
}

/**
 * Comment
 */
function startCounter(_id,startN,lps) {
    console.log(startN);
    _root = $("#"+_id);
    $(".hp_column").css({
        "min-height":"330px",
        "height":"auto"
    })
    myCount = parseInt(startN);
    LPS = parseInt(lps)/10;
    setInterval(rendercounter,100);
}
/**
 * Comment
 */
function rendercounter() {
    myCount = myCount+LPS;
    var currentCount =Math.round(myCount);
    var str  = addCommas(currentCount.toString().lpad(0,10));
    
    var str_arr = str.split("");
    var rollers_arr = []
    for(var X in str_arr){
        rollers_arr.push("<div class='cRoller'>"+str_arr[X]+"</div>")
    }
     
    var _html = "Since you've entered this website the world could have saved:";
    _html += "<div class='void'></div>";
    _html += rollers_arr.join("");
    _html += "<div class='void'></div>";
    _html += "Cubic meters of clean water<br/><br/>";
     
    _root.html(_html);
    $(".cRoller").css({
        
    })
}

String.prototype.lpad = function(padString, length) {
	var str = this;
    while (str.length < length)
        str = padString + str;
    return str;
}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}
