// JavaScript Document
//alert('good');
var st;

var news_item=0;
var selected_slide =0;
var thumbs = '';
var i;
var continue_check = 'yes'
var clicked = 'no'
var photo = new Array();
var news_text = new Array();
var link_text = new Array();
var button_text = new Array();
var button_slide = new Array();
var selected_slide = 0;


// # for first and last slides. This is the starting and ending to the slide show in case you want to skip beginning or ending slides
var first = 0;
var last = 7;


////
//Easy edits guide & examples
//
//Slide speed(in miliseconds make sure to end with ;)
//  var slide_speed = 5000;
//
//Slides- Make sure to enclose each edit after the = in ' ' and end with ; 
//  photo[#] = 'the image source for slide #';
//  news_text[#] = 'the news article for slide #';  
//  link_text[#] = 'the 'Read more' link for slide #';
//
//Buttons- Make sure they follow order, text & slides match up [#]. Buttons will be inserted in to table as the are read in (top down order of [#]
//   button_text[#] = 'What you want the button to say'
//   button_slide[#] = 'The slide # you want the button to go to'  previous/next are respective functions
////

////
//Speed of slides
////
var slide_speed = 7000;

////
//Link text (Read More...)
////
short_link = 'Read More...';

//Picture source
//   You can change, add, & manage pictures in the news folder by using joomla administrator media manager. 
//   Just make sure that the source and names match. Use 'none' for no image
////// '/images/8 housing.jpg'  //'/images/safehousing.jpg'
photo[0] = '/images/92 Pitt SUSY.jpg'  //'/images/8 housing.jpg'  //'/images/safehousing.jpg'
photo[1] = '/images/91 Virginia lawyer.JPG'
photo[2] = '/images/9 SRS SUSY.JPG'
photo[3] = '/images/8 New Beginnings.JPG'
photo[4] = '/images/7 job market.jpg'
photo[5] = '/images/6 Guardian ad litem.JPG'
photo[6] = '/images/5 Douglas county SUSY.JPG'
photo[7] = '/images/4 Diffenbaugh.jpg'

////
//Links
////
link_text[0] = '/news-articles/71-urgent/253-pitt-hosts-foster-youth-for-conference'  //'/news-articles/78-news/230-new-housing-for-foster-children-and-aging-out-youth'  //'/news-articles/78-news/171-great-successes-yielded-from-safe-housing-for-foster-youth'
link_text[1] = '/news-articles/71-urgent/252-virginia-lawyer-seeks-to-open-foster-care-non-profit'
link_text[2] = '/news-articles/71-urgent/251-srs-holds-discussion-forums-on-child-welfare'
link_text[3] = '/news-articles/71-urgent/250-new-beginnings-internships-give-at-risk-youth-experience'
link_text[4] = '/news-articles/71-urgent/249-job-market-proves-difficult-for-kids-leaving-foster-care'
link_text[5] = '/news-articles/71-urgent/248-guardian-ad-litem-volunteers-get-a-little-help'
link_text[6] = '/news-articles/71-urgent/247-douglas-county-saves-lawrence-srs-office'
link_text[7] = '/news-articles/71-urgent/246-diffenbaughs-novel-on-foster-care-the-language-of-flowers'

//Text to go with picture. 
//  Best not to use ' or " (unless in html)
//  for single quote '  use html code   &#39; 
//  for double quote "  use html code &quot;
//
// if font is too big enclose your text with <font size="1px"> TEXT </font>
////



news_text[0] = 'Pitt Hosts Foster Youth for Conference' //'New Housing for Foster Children and Aging Out Youth'  //'Great Successes Yielded from Safe Housing for Foster Youth'
news_text[1] = 'Virginia Lawyer Seeks to Open Foster Care Non-Profit'
news_text[2] = 'SRS Holds Discussion Forums on Child Welfare'
news_text[3] = 'New Beginnings Internships Give At-Risk Youth Experience'
news_text[4] = 'Job Market Proves Difficult for Kids Leaving Foster Care'
news_text[5] = 'Guardian ad Litem Volunteers Get a Little Help'
news_text[6] = 'Douglas County Saves Lawrence SRS Office'
news_text[7] = "Diffenbaugh's Novel on Foster Care, 'The Language of Flowers'"



//OLD///news_text[1] = 'Woman Taps Her Experience With Foster Care'
//OLD///news_text[2] = 'Life After Foster Care: All-Star Youth Share Their Stories'
//OLD///news_text[3] = 'With a Little Help, a Diploma';
//OLD///news_text[4] = 'Stories from the System';
//OLD///news_text[5] = 'Orlando Magic Executive goes from Foster Care in Independence to White House';
//OLD///news_text[6] = 'Scholarships Offered by the University of Phoenix';
//OLD///news_text[7] = 'Foster Care Numbers Drop as States Add Preventative Services';
//OLD///news_text[8] = 'Foster Children Begin Transition';
//OLD////news_text[7] = 'On Foster Youth Success Stories: Salute to Grads Who Defied the Odds';
//OLD////news_text[8] = 'Ordinary Americans Make a Difference in the Lives of Former Foster care Children';






//OLD////link_text[1] = '/index.php/news/78-news/150-woman-taps-her-experience-with-foster-care'
//OLD////link_text[2] = 'index.php/news/78-news/149-life-after-foster-care-all-star-youth-share-their-stories'
//OLD////link_text[3] = '/index.php/news/78-news/148-with-a-little-help-a-diploma-';
//OLD////link_text[4] = '/index.php/news/78-news/147-stories-from-the-system';
//OLD////link_text[5] = '/index.php/news/78-news/146-orlando-magic-executive-goes-from-foster-care-in-independence-to-white-house';
//OLD////link_text[6] = '/index.php/news/78-news/145-scholarships-offered-by-the-university-of-phoenix';
//OLD////link_text[7] = '/index.php/news/78-news/141-foster-care-numbers-drop';
//OLD////link_text[8] = '/index.php/news/78-news/142-foster-children-begin-transition';
//OLD////link_text[7] = '/index.php/news/78-news/143-on-foster-youth-success-stories-salute-to-grads-who-defied-the-odds';
//OLD////link_text[8] = '/index.php/news/71-urgent/144-ordinary-americans-make-a-difference-in-the-lives-of-former-foster-care-children';
////
//Be careful below
////


//preload our images to an array
var image_array = new Array();
var random_array = new Array();
	for (i = 0; i < photo.length;i++){
		image_array[i] = new Image();
		image_array[i].src = photo[i];


		//Random array
		random_array[i] = new Object();
		random_array[i].LinkText = link_text[i]
		random_array[i].NewsText = news_text[i]
		random_array[i].Photo = photo[i]
		//alert(photo[i])
		//alert('i  :'+i)
		//alert('Linktext  :'+random_array[i].LinkText)
		//alert('newsT  :'+random_array[i].NewsText)
		//alert('Photo  :'+random_array[i].Photo)

	};
fisherYates (random_array)


function fisherYates ( myArray ) {
   //array shuffling routine (see: http://sedition.com/perl/javascript-fy.html)
   var i = myArray.length;
   if ( i == 0 ) return false;
   while ( --i ) {
       var j = Math.floor( Math.random() * ( i + 1 ) );
       var tempi = myArray[i];
       var tempj = myArray[j];
       myArray[i] = tempj;
       myArray[j] = tempi;
   }
 
}




//random_array =  random_array.sort(randomSort2)



function randomSort2(a,b) {
    // Get a random number between 0 and 10
    var temp = parseInt( Math.random()*10 );

    // Get 1 or 0, whether temp is odd or even
    var isOddOrEven = temp%2;

    // Get +1 or -1, whether temp greater or smaller than 5
    var isPosOrNeg = temp>5 ? 1 : -1;

    // Return -1, 0, or +1
    return( isOddOrEven*isPosOrNeg );
}







//The main slider function that calls itself every slide_speed seconds
function slider(selected_slide){







clicked='no';
thumbs = '';
//continue_check to see if we are mousing over
if (continue_check == 'yes'){lol = selected_slide;

    for (i = 0; i < photo.length;i++)
    {if (i == selected_slide){thumbs = thumbs+'<div id="div_highlight" onClick="click_slide('+i+')" style="cursor:pointer;"><img class="image_thumb" src="'+random_array[i].Photo+'" onMouseOver="stop_slide('+i+')" onMouseOut="continue_slide()"></div>';}
    else{
            
        thumbs = thumbs+'<div class="div_thumb" onClick="click_slide('+i+')" style="cursor:pointer;"><img class="image_thumb" src="'+random_array[i].Photo+'" onMouseOver="stop_slide('+i+')" onMouseOut="continue_slide()"></div>';
    };

    document.getElementById("thumb_box").innerHTML= thumbs 
};

//create photo + news header div + and link
//this will be inserted after photo
html_header = '<div id="news_header"><b><a href='+random_array[lol].LinkText+ '>'+random_array[lol].NewsText +'</a></b></div>';
html_photo = '<a href="'+random_array[lol].LinkText+'"><img class="image_news" src="'+random_array[lol].Photo+'"></a>';

first_html = html_photo+html_header;


document.getElementById("photo_box").innerHTML= first_html;

continue_check == 'yes'
//Timer call
if (continue_check == 'yes'){
	news_item = news_item + 1;
	if (news_item >= photo.length){
		news_item = first;
		};
	
};
};
st = setTimeout('slider(news_item)', slide_speed);
}







//Mouse on
function stop_slide(selected_slide){//alert('mouse on');

continue_check = 'no';show_stop(selected_slide);};

//mouse on
function show_stop(slide){
html_header = '<div id="news_header"><b><a href='+random_array[slide].LinkText+ '>'+random_array[slide].NewsText+'</a></b></div>';
html_photo = '<a href="'+random_array[slide].LinkText+'"><img class="image_news" src="'+random_array[slide].Photo+'"></a>';

first_html = html_photo+html_header;


document.getElementById("photo_box").innerHTML= first_html
if (slide == (news_item-1)){}
else{if (clicked=='yes'){}
else{
document.getElementById("div_highlight").id="div_thumb";}
};
};

//Mouse off
function continue_slide(){
continue_check = 'yes';show_slide((news_item -1));};

//mouse off
function show_slide(slide){

if (clicked != 'yes'){
continue_check='yes';
if (slide==0){slide = last}
html_header = '<div id="news_header"><b><a href='+random_array[slide].LinkText+ '>'+random_array[slide].NewsText +'</a></b></div>';
html_photo = '<a href="'+random_array[slide].LinkText+'"><img class="image_news" src="'+random_array[slide].Photo+'"></a>';

first_html = html_photo+html_header;
//news_and_more = '<div id="news_header"><b><a href='+link_text[slide]+ '>'+news_text[slide] +'</a></b></div>';
document.getElementById("photo_box").innerHTML= first_html//'<a href="'+link_text[slide]+'"><img class="image_news" src="'+photo[slide]+'"></a>'+news_and_more;
if (document.getElementById("div_thumb")){
document.getElementById("div_thumb").id="div_highlight"};
continue_check ='yes';
    };
if (clicked=='yes'){//alert('click');
select_div(slide+1);}
};

function click_slide(slide){clicked='yes';if (slide == news_item){select_div(slide)};
news_item = slide;//select_div(slide);
//open the link
location.href= random_array[slide].LinkText 
};


function select_div(slide){//alert('redraw');
thumbs = '';


    for (i = 0; i < photo.length;i++)
    {if (i == slide){thumbs = thumbs+'<div id="div_highlight" onClick="click_slide('+i+')" style="cursor:pointer;"><img class="image_thumb" src="'+random_array[i].Photo+'"   onMouseOver="stop_slide('+i+')" onMouseOut="continue_slide()"></div>';
    html_header = '<div id="news_header"><b><a href='+random_array[slide].LinkText+ '>'+random_array[slide].NewsText +'</a></b></div>';
    html_photo = '<a href="'+random_array[slide].LinkText+'"><img class="image_news" src="'+random_array[slide].Photo+'"></a>';

    first_html = html_photo+html_header;


document.getElementById("photo_box").innerHTML= first_html}
    else{
            
        thumbs = thumbs+'<div class="div_thumb" onClick="click_slide('+i+')" style="cursor:pointer;"><img class="image_thumb" src="'+random_array[i].Photo+'" onMouseOver="stop_slide('+i+')" onMouseOut="continue_slide()" style="cursor:pointer;"></div>';
    };

    document.getElementById("thumb_box").innerHTML= thumbs ;
   
};
};


window.onload = function() {
	
	slider(0)
	}
