// JavaScript Document
//author Scott Shaper

//global variables
var picNum = 0;
var timeOutNum = 4000;
var timeoutID;
var count = 0;
var manualRotateToggle = true;



function styleSwitcher(a,b) {
		var exp = new Date();
		var oneYearFromNow = exp.getTime() + (365*24*60*60*1000);
		exp.setTime(oneYearFromNow);
		document.cookie = "sitestyle = "+a+";expires=" + exp.toGMTString()+";path=/;domain=.www.emich.edu";
		redirect(b);
}

function redirect(b){
	window.location = "http://"+b;
}

function showHide(a){
	if ($('#showhide'+a).is('.show')){
		$('#exp'+a).html('<img src="http://www.emich.edu/admin/images/toplevel_images/general_images/plus.gif" alt="plus" />');
		$('#showhide'+a).removeClass();
		$('#showhide'+a).addClass('hide');
	}
	else if ($('#showhide'+a).is('.hide')){
		$('#exp'+a).html('<img src="http://www.emich.edu/admin/images/toplevel_images/general_images/minus.gif" alt="minus" />');
		$('#showhide'+a).removeClass();
		$('#showhide'+a).addClass('show');
	}
}


function setIndexPage(){
	count = $('#count').val();
	for (i=0;i<count;i++){
		$('#pic'+i).hide();
	}
	$('#pic0').show();
        picNum++;
        window.setTimeout('rotateTags()', timeOutNum);
        $('#play_pause').bind('click',function(){manualRotate()});
        $('#step_left').bind('click',function(){moveLeft()});
        $('#step_right').bind('click',function(){moveRight()});
}

function getContent(a){
	//a = the content array number
	count = $('#count').val();
	for (i=0;i<count;i++){
		$('#pic'+i).hide();
	}
	$('#pic'+a).show();
}

function manualRotate()
{
    if (manualRotateToggle)
        {
            $('#play_pause').html('<img src="admin/images/ad_controls/play_sm.png" width="14" height="12" alt="pause_play"/>');
            $('#step_right').html('<img src="admin/images/ad_controls/right_sm_green.png" width="14" height="12" alt="pause_play"/>');
            $('#step_left').html('<img src="admin/images/ad_controls/left_sm_green.png" width="14" height="12" alt="pause_play"/>');
            window.clearTimeout(timeoutID);
            manualRotateToggle = false;
        }
    else
        {
            $('#play_pause').html('<img src="admin/images/ad_controls/pause_sm.png" width="14" height="12" alt="pause_play"/>');
            $('#step_right').html('<img src="admin/images/ad_controls/right_sm.png" width="14" height="12" alt="pause_play"/>');
            $('#step_left').html('<img src="admin/images/ad_controls/left_sm.png" width="14" height="12" alt="pause_play"/>');
            rotateTags();
            manualRotateToggle = true;
        }
}

function moveLeft()
{
    if (!manualRotateToggle)
        {
            picNum--;
            if (picNum <= -1)
                {
                    $('#pic'+(picNum+1)).hide();
                    picNum = count-1;
                    $('#pic'+picNum).show();
                }
             else
                 {
                     $('#pic'+(picNum+1)).hide();
                     $('#pic'+picNum).show();
                 }
        }
}

function moveRight()
{
    if (!manualRotateToggle)
        {
            //picNum++;
            if (picNum >= count)
                {
                    
                    $('#pic'+(picNum-1)).hide();
                    picNum = 0;
                    $('#pic'+picNum).show();
                    
                }
             else
                 {
                     
                     $('#pic'+(picNum-1)).hide();
                     $('#pic'+picNum).show();
                 }
        }
        picNum++;
}

function rotateTags()
{

    if (picNum == 0)
        {
            $('#pic'+(count-1)).hide();
            $('#pic'+picNum).show();
            picNum++;
        }

    else if (picNum == (count-1))
        {
            $('#pic'+(picNum-1)).hide();
            $('#pic'+picNum).show();
            picNum = 0;
        }
    else
        {
           $('#pic'+(picNum-1)).hide();
           $('#pic'+picNum).show();
           picNum++;
        }
    timeoutID = window.setTimeout('rotateTags()', timeOutNum);
}

