﻿// Javscript needed for stories/headlines

currID_MH = ''

var HidingTimer_MH
var HidingTimer_TS
var curr_story
var curr_story_back
var running
var numstories_global

function moreheadlines_show (id, go) {
    clearTimeout(HidingTimer_MH)
    if (go) {
        if ((currID_MH != id) && (currID_MH != '')) {
            moreheadlines_hide (currID_MH)
        }
        document.getElementById('divMoreHeadline_more_' + id).style.display = 'block';
        currID_MH = id
    } else {
        HidingTimer_MH = setTimeout('moreheadlines_show (' + id + ', true)', 1000);    
    }
}

function moreheadlines_hide (id) {
    document.getElementById('divMoreHeadline_more_' + id).style.display = 'none';
}

function moreheadlines_stoptimer() {
    clearTimeout(HidingTimer_MH)
}

function ICS_rotate(storyid, numstories, stop, speed) {

    if (speed == '') {
        speed = 4000
    }

    for (var x = 1; x <= numstories; x++) {
        document.getElementById('rotImage_' + x).style.display = 'none';
        document.getElementById('rotStory_' + x).style.display = 'none';
        document.getElementById('rotHeadline_' + x).className = 'divTopStory_Rotate_ICS_Headlines'
    }
    document.getElementById('rotImage_' + storyid).style.display = 'block';
    document.getElementById('rotStory_' + storyid).style.display = 'block';
    document.getElementById('rotHeadline_' + storyid).className += ' divTopStory_Rotate_ICS_Headlines_selected'
    
    storyid += 1
    if (storyid > numstories) {storyid = 1}
    
    if (!stop) {
	    HidingTimer_TS = setTimeout('ICS_rotate(' + storyid + ',' + numstories + ',0,' + speed + ')', speed);
	} else {
		clearTimeout(HidingTimer_TS);
	}
    
}     


function CS_rotate_stop(img) {
	if (running) { 
		clearTimeout(HidingTimer_TS);
		running = false;
		rollover(img,true,false)
	} else {
		rollover(img,false,false)
		running = true;
		HidingTimer_TS = setTimeout('CS_rotate(' + curr_story + ',' + numstories_global + ',0,4000)', 4000);
	}
}

function CS_rotate_pause() {
	if (running) { 
		clearTimeout(HidingTimer_TS);
		running = false;
		
	} else {
		running = true;
		HidingTimer_TS = setTimeout('CS_rotate(' + curr_story + ',' + numstories_global + ',0,4000)', 4000);
	}
}

function CS_rotate_direction(dir) {
    clearTimeout(HidingTimer_TS);
    if (dir == 'up') {
        
        if (curr_story <=0) {curr_story = 2}
        if (curr_story > numstories_global) {
        
        } else {
            CS_rotate(curr_story,numstories_global,true,4000)
        }
    } else {
             
        curr_story_back = curr_story_back - 2
        if (curr_story_back <= 0) {
            curr_story_back = numstories_global
        } 
        if (curr_story_back > numstories_global) {
        
        } else {
            CS_rotate(curr_story_back,numstories_global,true,4000)
        }
        
    }
}

function CS_rotate(storyid, numstories, stop, speed_cs) {

	running = true

    if (speed_cs == undefined) {
        speed_cs = 4000
    }

    for (var x = 1; x <= numstories; x++) {
        document.getElementById('rotStory_' + x).style.display = 'none';
        document.getElementById('rotHeadline_' + x).className = 'divTopStory_Rotate_CS_Headlines';
        document.getElementById('rotHeadline2_' + x).className = 'divTopStory_Rotate_TV_Headlines';
        document.getElementById('rotImage_' + x).style.display = 'none';
        document.getElementById('rotHeadlineImg_' + x).src='/images/thumbbuttons_' + x + '.gif';
    }
    document.getElementById('rotStory_' + storyid).style.display = 'block';
    document.getElementById('rotHeadline_' + storyid).className += ' divTopStory_Rotate_CS_Headlines_selected'
    document.getElementById('rotHeadline2_' + storyid).className += ' divTopStory_Rotate_TV_Headlines_selected'
    document.getElementById('rotHeadlineImg_' + storyid).src='/images/thumbbuttons_' + storyid + 'b.gif'
    document.getElementById('rotImage_' + storyid).style.display = 'block';
    
    storyid += 1
    curr_story_back = storyid
    if (storyid > numstories) {storyid = 1}
    
    if (!stop) {
	    HidingTimer_TS = setTimeout('CS_rotate(' + storyid + ',' + numstories + ',0,' + speed_cs + ')', speed_cs);
	} else {
		running = false
		clearTimeout(HidingTimer_TS);
	}
	
	curr_story = storyid
	numstories_global = numstories
    
}

function TV_rotate(storyid, numstories, stop, speed_tv) {

    if (speed_tv == undefined) {
        speed_tv = 4000
    }

    for (var x = 1; x <= numstories; x++) {
        document.getElementById('rotStory_' + x).style.display = 'none';
        document.getElementById('rotStory_bm_' + x).style.display = 'none';
        document.getElementById('rotHeadline_' + x).className = 'divTopStory_Rotate_TV_Headlines'
    }
    document.getElementById('rotStory_' + storyid).style.display = 'block';
    document.getElementById('rotStory_bm_' + storyid).style.display = 'block';
    document.getElementById('rotHeadline_' + storyid).className += ' divTopStory_Rotate_TV_Headlines_selected'
    
    storyid += 1
    if (storyid > numstories) {storyid = 1}
    
    if (!stop) {
	    HidingTimer_TS = setTimeout('TV_rotate(' + storyid + ',' + numstories + ',0,' + speed_tv + ')', speed_tv);
	} else {
		clearTimeout(HidingTimer_TS);
	}
    
} 

function CSHeadlines_rotate(storyid, numstories, stop, speed_cs) {

    if (speed_cs == undefined) {
        speed_cs = 4000
    }

    for (var x = 1; x <= numstories; x++) {
        document.getElementById('rotStory1_' + x).style.display = 'none';
        document.getElementById('rotHeadline1_' + x).className = 'divHeadlines_Rotate_CS_Headlines';
        document.getElementById('rotImage1_' + x).style.display = 'none';
        document.getElementById('rotHeadlineImg1_' + x).src='/images/headlinethumb_' + x + '.gif';
    }
    document.getElementById('rotStory1_' + storyid).style.display = 'block';
    document.getElementById('rotHeadline1_' + storyid).className += ' divHeadlines_Rotate_CS_Headlines_selected'
    document.getElementById('rotHeadlineImg1_' + storyid).src='/images/headlinethumb_' + storyid + 'b.gif'
    document.getElementById('rotImage1_' + storyid).style.display = 'block';
    
    storyid += 1
    if (storyid > numstories) {storyid = 1}
    
    if (!stop) {
	    HidingTimer_TS = setTimeout('CSHeadlines_rotate(' + storyid + ',' + numstories + ',0,' + speed_cs + ')', speed_cs);
	} else {
		clearTimeout(HidingTimer_TS);
	}
    
}             