﻿//** Featured Content Slider script- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
//** Last updated: Feb 28th- 07- Added ability to customize pagination links' text
//http://www.dynamicdrive.com/dynamicindex17/featuredcontentslider.htm#pinterface

////Ajax related settings
var csbustcachevar = 0 //bust potential caching of external pages after initial Ajax request? (1=yes, 0=no)
var csloadstatustext = "<img src='loading.gif' /> Requesting content..." //HTML to indicate Ajax page is being fetched
var csexternalfiles = [] //External .css or .js files to load to style the external content(s), if any. Separate multiple files with comma ie: ["cat.css", dog.js"]

////NO NEED TO EDIT BELOW////////////////////////
var enablepersist = true
var slidernodes = new Object() //Object array to store references to each content slider's DIV containers (<div class="contentdiv">)
var csloadedobjects = "" //Variable to store file names of .js/.css files already loaded (if Ajax is used)

function ContentSlider(sliderid, autorun, customPaginateText, customNextText, tabsLinks) {

    var slider = document.getElementById(sliderid)

    if (typeof customPaginateText != "undefined" && customPaginateText != "") //Custom array of pagination links text defined?
        slider.paginateText = customPaginateText
    if (typeof customNextText != "undefined" && customNextText != "") //Custom HTML for "Next" link defined?
        slider.nextText = customNextText
    if (typeof tabsLinks != "undefined" && tabsLinks != "")
        slider.tabsLinks = tabsLinks
    slidernodes[sliderid] = [] //Array to store references to this content slider's DIV containers (<div class="contentdiv">)
    ContentSlider.loadobjects(csexternalfiles) //Load external .js and .css files, if any
    var alldivs = slider.getElementsByTagName("div")

    for (var i = 0; i < alldivs.length; i++) {
        if (alldivs[i].className == "contentdiv") {

            slidernodes[sliderid].push(alldivs[i]) //add this DIV reference to array
            if (typeof alldivs[i].getAttribute("rel") == "string") //If get this DIV's content via Ajax (rel attr contains path to external page)
                ContentSlider.ajaxpage(alldivs[i].getAttribute("rel"), alldivs[i])
        }
    }
    //--------------------------------------------------
    ContentSlider.pause = function() {
        // This method stops the slideshow if it is automatically running.

        if (window[sliderid + "timer"] != 0) {

            clearTimeout(window[sliderid + "timer"]);
            window[sliderid + "timer"] = 0;

        }
    }
    //--------------------------------------
    ContentSlider.buildpagination_mill(sliderid)
    var loadfirstcontent = true
    if (enablepersist && getCookieSlider(sliderid) != "") { //if enablepersist is true and cookie contains corresponding value for slider
        var cookieval = getCookieSlider(sliderid).split(":") //process cookie value ([sliderid, int_pagenumber (div content to jump to)]
        if (document.getElementById(cookieval[0]) != null && typeof slidernodes[sliderid][cookieval[1]] != "undefined") { //check cookie value for validity
            ContentSlider.turnpage(cookieval[0], parseInt(cookieval[1])) //restore content slider's last shown DIV
            loadfirstcontent = false
        }
    }

    if (loadfirstcontent == true) //if enablepersist is false, or cookie value doesn't contain valid value for some reason (ie: user modified the structure of the HTML)
        ContentSlider.turnpage(sliderid, 0) //Display first DIV within slider

    //if (typeof autorun=="number" && autorun>0) //if autorun parameter (int_miliseconds) is defined, fire auto run sequence
    //	window[sliderid+"timer"]=setTimeout(function(){ContentSlider.autoturnpage(sliderid, autorun)}, autorun)
}

ContentSlider.buildpagination = function(sliderid) {
    var slider = document.getElementById(sliderid)
    var paginatediv = document.getElementById("ctl00_ctl11_g_b0019025_4226_4fea_974e_bf81ca5e214a_paginate-slider1") //reference corresponding pagination DIV for slider
    if (paginatediv == null)
        paginatediv = document.getElementById("ctl00_ctl10_g_b0019025_4226_4fea_974e_bf81ca5e214a_paginate-slider1") //reference corresponding pagination DIV for slider

    var pcontent = ""
    for (var i = 0; i < slidernodes[sliderid].length; i++) //For each DIV within slider, generate a pagination link
        pcontent += '<a href="#" onmouseover=\"ContentSlider.turnpage(\'' + sliderid + '\', ' + i + ');ContentSlider.pause(); return false\">' + (slider.paginateText ? slider.paginateText[i] : i + 1) + '</a> '
    pcontent += '<a href="#" style="font-weight: bold;" onmouseover=\"ContentSlider.turnpage(\'' + sliderid + '\', parseInt(this.getAttribute(\'rel\')));ContentSlider.pause(); return false\">' + (slider.nextText || "Next") + '</a>'
    paginatediv.innerHTML = pcontent
    paginatediv.onclick = function() { //cancel auto run sequence (if defined) when user clicks on pagination DIV
        if (typeof window[sliderid + "timer"] != "undefined")
            clearTimeout(window[sliderid + "timer"])
    }
}

function ChangePicSlider(sliderid, obj, word_old, word_new, leave_selected) {
    //alert(sliderid)
    var paginatelinks = document.getElementById("ctl00_ctl11_g_b0019025_4226_4fea_974e_bf81ca5e214a_paginate-slider1").getElementsByTagName("a") //Get pagination links
    var pagenumber = parseInt(paginatelinks[paginatelinks.length - 1].getAttribute("rel")) //Get page number of next DIV to show
    //alert(pagenumber)
    if (isNaN(pagenumber))
        pagenumber = 0;
    if (leave_selected == 1 && obj.src.indexOf("_0" + ((pagenumber - 1) * 2 + 1)) >= 0)
        return;
    //alert(obj.src)
    //  alert(obj.parent);  
    obj.className = 'cur';
    //obj.src=obj.src.replace(word_old,word_new)
    //alert(obj.src)
}

ContentSlider.buildpagination_mill = function(sliderid) {

    var slider = document.getElementById(sliderid)
    /*var paginatediv=document.getElementById("ctl00_ctl10_g_b0019025_4226_4fea_974e_bf81ca5e214a_paginate-slider1") //reference corresponding pagination DIV for slider
    var pcontent=""
    for (var i=0; i<slidernodes[sliderid].length; i++) //For each DIV within slider, generate a pagination link
    pcontent+='<a href="#" onClick=\"ContentSlider.turnpage(\''+sliderid+'\', '+i+'); return false\">'+(slider.paginateText? slider.paginateText[i] : i+1)+'</a> '
    pcontent+='<a href="#" style="font-weight: bold;" onClick=\"ContentSlider.turnpage(\''+sliderid+'\', parseInt(this.getAttribute(\'rel\'))); return false\">'+(slider.nextText || "Next")+'</a>'
    paginatediv.innerHTML=pcontent
    paginatediv.onclick=function(){ //cancel auto run sequence (if defined) when user clicks on pagination DIV
    if (typeof window[sliderid+"timer"]!="undefined")
    clearTimeout(window[sliderid+"timer"])
    }
	
	------------------------------------------------*/
    var slider = document.getElementById(sliderid)
    var paginatediv = document.getElementById("ctl00_ctl11_g_b0019025_4226_4fea_974e_bf81ca5e214a_paginate-slider1"); //+sliderid) //reference corresponding pagination DIV for slider
    var pcontent = "<table  border='0' cellpadding='0' cellspacing='0' class='hpMenu'><tr>"//+"\r\n";
    //alert(paginatediv);
    for (var i = 0; i < slidernodes[sliderid].length; i++) //For each DIV within slider, generate a pagination link
    {
        pcontent += "<td><div>";
        pcontent += '<a href="' + slider.tabsLinks[i] + '" onmouseover=\"ContentSlider.turnpage(\'' + sliderid + '\', ' + i + ');ContentSlider.pause(); return false\">' + (slider.paginateText ? slider.paginateText[i] : i + 1) + '</a> ';
        //pcontent+='<a href="#" onClick=\"ContentSlider.turnpage_mill(\''+sliderid+'\', '+i+'); return false\">'+"<img onmouseover='ChangePicSlider(\""+sliderid+"\",this,\"buttons1_\",\"buttons_\",1)' onmouseout='ChangePicSlider(\""+sliderid+"\",this,\"buttons_\",\"buttons1_\",1)' style='border:0px;width:28px;height:22px;'  src='/IDF/Rsrc/images/buttons1_0"+eval(i*2+1)+".jpg' alt='"+eval(i+1)+"'>" +'</a> '
        pcontent += "</div></td>";
    }
    //pcontent+='<a href="#" style="font-weight: bold;" onClick=\"ContentSlider.turnpage(\''+sliderid+'\', parseInt(this.getAttribute(\'rel\'))); return false\">'+(slider.nextText || "Next")+'</a>'
    pcontent += "</tr></table>"
    paginatediv.innerHTML = pcontent
    /*paginatediv.onclick=function(){ //cancel auto run sequence (if defined) when user clicks on pagination DIV
    if (typeof window[sliderid+"timer"]!="undefined")
    clearTimeout(window[sliderid+"timer"])
    }*/
}
/*source
ContentSlider.turnpage=function(sliderid, thepage){
var paginatelinks=document.getElementById("paginate-"+sliderid).getElementsByTagName("a") //gather pagination links
for (var i=0; i<slidernodes[sliderid].length; i++){ //For each DIV within slider
paginatelinks[i].className="" //empty corresponding pagination link's class name
slidernodes[sliderid][i].style.display="none" //hide DIV
}
paginatelinks[thepage].className="selected" //for selected DIV, set corresponding pagination link's class name
if (enabletransition){
if (window[sliderid+"fadetimer"])
clearTimeout(window[sliderid+"fadetimer"])
this.setopacity(sliderid, 0.1)
}
slidernodes[sliderid][thepage].style.display="block" //show selected DIV
if (enabletransition)
this.fadeup(sliderid, thepage)
//Set "Next" pagination link's (last link within pagination DIV) "rel" attribute to the next DIV number to show
paginatelinks[paginatelinks.length-1].setAttribute("rel", thenextpage=(thepage<paginatelinks.length-2)? thepage+1 : 0)
if (enablepersist)
setCookie(sliderid, sliderid+":"+thepage)
}*/

ContentSlider.turnpage = function(sliderid, thepage) {
    var paginatetds = document.getElementById("ctl00_ctl11_g_b0019025_4226_4fea_974e_bf81ca5e214a_paginate-slider1").getElementsByTagName("td") //gather pagination links
    var paginatelinks = document.getElementById("ctl00_ctl11_g_b0019025_4226_4fea_974e_bf81ca5e214a_paginate-slider1").getElementsByTagName("a") //gather pagination links
    for (var i = 0; i < slidernodes[sliderid].length; i++) { //For each DIV within slider
        paginatetds[i].className = "" //empty corresponding pagination link's class name
        slidernodes[sliderid][i].style.display = "none" //hide DIV
    }
    paginatetds[thepage].className = "cur" //for selected DIV, set corresponding pagination link's class name
    slidernodes[sliderid][thepage].style.display = "block" //show selected DIV
    //Set "Next" pagination link's (last link within pagination DIV) "rel" attribute to the next DIV number to show
    paginatelinks[paginatelinks.length - 1].setAttribute("rel", thenextpage = (thepage < paginatelinks.length - 1) ? thepage + 1 : 0)
    if (enablepersist)
        setCookieSlider(sliderid, sliderid + ":" + thepage)
}

ContentSlider.autoturnpage = function(sliderid, autorunperiod) {
    var paginatelinks = document.getElementById("ctl00_ctl11_g_b0019025_4226_4fea_974e_bf81ca5e214a_paginate-slider1").getElementsByTagName("a") //Get pagination links
    var nextpagenumber = parseInt(paginatelinks[paginatelinks.length - 1].getAttribute("rel")) //Get page number of next DIV to show
    ContentSlider.turnpage(sliderid, nextpagenumber) //Show that DIV
    window[sliderid + "timer"] = setTimeout(function() { ContentSlider.autoturnpage(sliderid, autorunperiod) }, autorunperiod)
}

/*ContentSlider.turnpage_mill=function(sliderid, thepage){
var paginatelinks=document.getElementById("ctl00_ctl10_g_b0019025_4226_4fea_974e_bf81ca5e214a_paginate-slider1").getElementsByTagName("a") //gather pagination links
	
for (var i=0; i<slidernodes[sliderid].length; i++){ //For each DIV within slider
//paginatelinks[i].className="" //empty corresponding pagination link's class name
//alert(paginatelinks[i].firstChild.src)
		
		
ChangePicSlider(sliderid,paginatelinks[i].firstChild,"buttons_","buttons1_",0);
alert(slidernodes[sliderid][i]);
slidernodes[sliderid][i].style.display="none" //hide DIV
}
//paginatelinks[thepage].className="selected" //for selected DIV, set corresponding pagination link's class name
//alert(thepage);
//alert(paginatelinks[thepage].firstChild.src);
ChangePicSlider(sliderid,paginatelinks[thepage].firstChild,"buttons1_","buttons_",0);

slidernodes[sliderid][thepage].style.display="block" //show selected DIV
//Set "Next" pagination link's (last link within pagination DIV) "rel" attribute to the next DIV number to show
paginatelinks[paginatelinks.length-1].setAttribute("rel", thenextpage=(thepage<paginatelinks.length-1)? thepage+1 : 0) //if next utton exists: (thepage<paginatelinks.length-2)? thepage+1 : 0
if (enablepersist)
setCookieSlider(sliderid, sliderid+":"+thepage)
}*/

ContentSlider.autoturnpage_mill = function(sliderid, autorunperiod) {
    var paginatelinks = document.getElementById("ctl00_ctl11_g_b0019025_4226_4fea_974e_bf81ca5e214a_paginate-slider1").getElementsByTagName("a") //Get pagination links
    var nextpagenumber = parseInt(paginatelinks[paginatelinks.length - 1].getAttribute("rel")) //Get page number of next DIV to show
    ContentSlider.turnpage(sliderid, nextpagenumber) //Show that DIV
    window[sliderid + "timer"] = setTimeout(function() { ContentSlider.autoturnpage_mill(sliderid, autorunperiod) }, autorunperiod)
}

function getCookieSlider(Name) {
    var re = new RegExp(Name + "=[^;]+", "i"); //construct RE to search for target name/value pair
    if (document.cookie.match(re)) //if cookie found
        return document.cookie.match(re)[0].split("=")[1] //return its value
    return ""
}

function setCookieSlider(name, value) {
    document.cookie = name + "=" + value
}

////////////////Ajax Related functions //////////////////////////////////

ContentSlider.ajaxpage = function(url, thediv) {
    var page_request = false
    var bustcacheparameter = ""
    if (window.XMLHttpRequest) // if Mozilla, Safari etc
        page_request = new XMLHttpRequest()
    else if (window.ActiveXObject) { // if IE
        try {
            page_request = new ActiveXObject("Msxml2.XMLHTTP")
        }
        catch (e) {
            try {
                page_request = new ActiveXObject("Microsoft.XMLHTTP")
            }
            catch (e) { }
        }
    }
    else
        return false
    thediv.innerHTML = csloadstatustext
    page_request.onreadystatechange = function() {
        ContentSlider.loadpage(page_request, thediv)
    }
    if (csbustcachevar) //if bust caching of external page
        bustcacheparameter = (url.indexOf("?") != -1) ? "&" + new Date().getTime() : "?" + new Date().getTime()
    page_request.open('GET', url + bustcacheparameter, true)
    page_request.send(null)
}

ContentSlider.loadpage = function(page_request, thediv) {
    if (page_request.readyState == 4 && (page_request.status == 200 || window.location.href.indexOf("http") == -1))
        thediv.innerHTML = page_request.responseText
}

ContentSlider.loadobjects = function(externalfiles) { //function to load external .js and .css files. Parameter accepts a list of external files to load (array)
    for (var i = 0; i < externalfiles.length; i++) {
        var file = externalfiles[i]
        var fileref = ""
        if (csloadedobjects.indexOf(file) == -1) { //Check to see if this object has not already been added to page before proceeding
            if (file.indexOf(".js") != -1) { //If object is a js file
                fileref = document.createElement('script')
                fileref.setAttribute("type", "text/javascript");
                fileref.setAttribute("src", file);
            }
            else if (file.indexOf(".css") != -1) { //If object is a css file
                fileref = document.createElement("link")
                fileref.setAttribute("rel", "stylesheet");
                fileref.setAttribute("type", "text/css");
                fileref.setAttribute("href", file);
            }
        }
        if (fileref != "") {
            document.getElementsByTagName("head").item(0).appendChild(fileref)
            csloadedobjects += file + " " //Remember this object as being already added to page
        }
    }
}
