// JavaScript Document
function getBaseURL() {
    var url = location.href;  // entire url including querystring - also: window.location.href;
    var baseURL = url.substring(0, url.indexOf('/', 14));


    if (baseURL.indexOf('http://localhost') != -1) {
        // Base Url for localhost
        var url = location.href;  // window.location.href;
        var pathname = location.pathname;  // window.location.pathname;
        var index1 = url.indexOf(pathname);
        var index2 = url.indexOf("/", index1 + 1);
        var baseLocalUrl = url.substr(0, index2);

        return baseLocalUrl + "/";
    }
    else {
        // Root Url for domain name
        return baseURL + "/";
    }

}
var slideShowObj = function(arrdiv, arrdiv2) {
    l = 0;
    w = -373;
    l1 = 0;
    w1 = 373;
    var a;
    var b;
    var c;
    ts_i = 0;
    j = 1;
    var arrcount = arrdiv.length;
    //alert(arrcount)
    var j1;
    var lock = false;
    var lock1 = false;
    this.move = function() {
        try {
			var agent=navigator.userAgent;
            if(agent.indexOf('iPhone')>0){
				l += 373;
	            w += 373;
			}
			else{
				l += 20;
	            w += 20;
			}
            //div image slide
            document.getElementById(arrdiv[ts_i]).style.left = l + "px";
            document.getElementById(arrdiv[j]).style.left = w + "px";
            //div title,shortLead slide
            document.getElementById(arrdiv2[ts_i]).style.left = l + "px";
            document.getElementById(arrdiv2[j]).style.left = w + "px";
            lock = true;
            if (l >= 373) {
                window.clearInterval(this.a);
                document.getElementById(arrdiv[ts_i]).style.left = "-373px";
                document.getElementById(arrdiv2[ts_i]).style.left = "-373px";
                document.getElementById(arrdiv[j]).style.left = "0px";
                document.getElementById(arrdiv2[j]).style.left = "0px";
                ts_i = ts_i + 1;
                if (ts_i == arrcount) {
                    ts_i = 0;
                }
                if (ts_i < arrcount - 1) {
                    j = ts_i + 1;
                }
                else if (ts_i == arrcount - 1) {
                    j = 0
                }
                l = 0;
                w = -373;

                //b=setTimeout("a=setInterval('move()',20)",5000);
                obj.b = setTimeout("obj.a=setInterval('obj.move()',30)", 10000);
                lock = false;
            }
        } catch (err) { return; }
    }
    this.callMove2 = function() {
        if (lock1 == true) {
            return false;
        }
        this.clearMove();
        if (ts_i <= arrcount - 2) {
            j = ts_i + 1;
        }
        else {
            j = 0;
        }
        obj.b = setTimeout("obj.a=setInterval('obj.move()',20)", 10);
        lock1 = true;
        setTimeout('obj.openlock()', 1000);
    }
    this.clearMove = function() {
        clearInterval(obj.a);
        clearTimeout(obj.b);
    }
    this.openlock = function() {
        lock1 = false;
    }
    this.callMove1 = function() {
        if (lock1 == true) {
            return false;
        }
        if (lock == false) {
            this.clearMove();
            if (ts_i > 0) {
                j1 = ts_i - 1;
            }
            else if (ts_i == 0) {
                j1 = arrcount - 1
            }
            //obj.c = setInterval('obj.move1()', 20);
            obj.c = setInterval('obj.move1()', 15);
            //alert('');
        }
        lock1 = true;
        setTimeout('obj.openlock()', 1000);

    }
    this.move1 = function() {
        l1 -= 20;
        w1 -= 20;
        lock = true;
        //div image slide
        document.getElementById(arrdiv[ts_i]).style.left = l1 + "px";
        document.getElementById(arrdiv[j1]).style.left = w1 + "px";
        //div title,shortLead slide
        document.getElementById(arrdiv2[ts_i]).style.left = l1 + "px";
        document.getElementById(arrdiv2[j1]).style.left = w1 + "px";
        if (l1 <= -373) {
            document.getElementById(arrdiv[j1]).style.left = "0px";
            document.getElementById(arrdiv2[j1]).style.left = "0px";
            clearInterval(this.c);
            ts_i = ts_i - 1;
            if (ts_i < 0) {
                ts_i = arrcount - 1;
            }
            l1 = 0;
            w1 = 373;
            this.callMove();
            lock = false;
        }
    }
    this.callMove = function() {
        if (ts_i < arrcount) {
-1
            j = ts_i + 1;
        }
        else if (ts_i == arrcount - 1) {
            j = 0
        }
        //b=setTimeout("a=setInterval('move()',10)",5000);
        obj.b = setTimeout("obj.a=setInterval('obj.move()',20)", 2000);
    }
    this.refobj = function(refobj) {
        obj = refobj;
    }
}
function createHTML(arItemTS) {
    //alert(arItemTS);
    iTSCount = arItemTS.length - 1;
    var sHTML = '';
    var arrdiv = new Array();
    var arrdiv2 = new Array();
    for (var i = 0; i <= iTSCount; i++) {
        arrdiv[i] = "div" + i;
        arrdiv2[i] = "div_" + i;
    }
	//'+getBaseURL()+'/
    sHTML = sHTML.concat('<div class="HomeTopStoryBorder HomeTopStoryBorder1"></div>');
    sHTML = sHTML.concat('<div class="HomeTopStoryBorder HomeTopStoryBorder2"></div>');
    sHTML = sHTML.concat('<div class="HomeTopStoryBorder HomeTopStoryBorder3"></div>');
    sHTML = sHTML.concat('<div class="HomeTopStoryBorder HomeTopStoryBorder4"></div>');
    sHTML = sHTML.concat('<div id="imgButton"><img src="/images/iconprev.gif" onclick="obj.callMove1();" /><img src="/images/iconnext.gif" onclick="obj.callMove2();" /></div>');
    sHTML = sHTML.concat('<div id="div0"><a href="' + arItemTS[0][5] + '" title="' + arItemTS[0][2] + '"><img src="' + arItemTS[0][1] + arItemTS[0][4] + '" alt="' + arItemTS[0][2] + '" width="280" height="230" class="STSimg" /></a></div>');
    for (var i = 1; i <= iTSCount; i++) {
        sHTML = sHTML.concat('	<div class="divImgTS" id="div' + i + '"><a href="' + arItemTS[i][5] + '" title="' + arItemTS[i][2] + '"><img src="' + arItemTS[i][1] + arItemTS[i][4] + '" alt="' + arItemTS[i][2] + '" width="280" height="230" class="STSimg" /></a></div>');
    }
    sHTML = sHTML.concat('	<div id="div_0"><div class="STSdiv1" align=center ><a href="' + arItemTS[0][5] + '" onfocus="this.blur();" class="divTitleTS" title="' + arItemTS[0][2] + '">' + arItemTS[0][2] + '</a></div>');
    sHTML = sHTML.concat(' <div class="Content">' + arItemTS[0][3] + '</div>');
    sHTML = sHTML.concat(' </div>')
    for (var i = 1; i <= iTSCount; i++) {
        sHTML = sHTML.concat('	<div class="divContTS" id="div_' + i + '"><div class="divTitleTS" align=center><a href="' + arItemTS[i][5] + '" onfocus="this.blur();" class="divTitleTS" title="' + arItemTS[i][2] + '">' + arItemTS[i][2] + '</a></div>');
        sHTML = sHTML.concat(' <div class="Content">' + arItemTS[i][3] + '</div>');
        sHTML = sHTML.concat(' </div>')
    }
    document.getElementById("divTS").innerHTML = sHTML;
    slideShowObj1 = new slideShowObj(arrdiv, arrdiv2, 280);
    slideShowObj1.b = setTimeout("slideShowObj1.a=window.setInterval('slideShowObj1.move()',20)", 10000);
    slideShowObj1.refobj(slideShowObj1);
    //iTSCur=0;
}