function updatePrintHref()
{
	var currentHref = document.getElementById("printView").href;
	currentHref = currentHref.substring(currentHref.lastIndexOf("/")+1);
	currentHref = currentHref.substring(0,currentHref.indexOf("?"));

	var extraHref='';

	if(window.location.search=='')
	{
		extraHref= currentHref + "?printView=true";
	}
	else{
		extraHref= currentHref + window.location.search + "&printView=true";
	}
	document.getElementById("printView").href = extraHref;
}

function scriptInit() {
if (!document.getElementById) {
 return;
 }
}
function addEvent(elm, evType, fn, useCapture) {
	if (elm.addEventListener) {
	elm.addEventListener(evType, fn, useCapture);
	return true;
	} else if (elm.attachEvent) {
	var r = elm.attachEvent('on' + evType, fn);
	return r;
	} else {
	elm['on' + evType] = fn;
	}
}
function checkActive() {
	var a = document.getElementsByTagName("a");
	var l = window.location.href;
	var p = new Array();
	p = l.split("/")
	var x = p[3];
	for(var i=0; i < a.length; i++) {
	h = a[i].href;
	var d = new Array();
	d = h.split("/");
	var k = d[3];
	if (k == x) {
if(x != ""){
	a[i].setAttribute("class", "active");
	a[i].setAttribute("className", "active");
}
if(x == "People"){
	a[3].setAttribute("class", "active");
	a[3].setAttribute("className", "active");
}
		}
	}
}
addEvent(window, 'load', checkActive, false);

//SUCCESS STORIES:
( function () {
    function addCSSRule (selectorText, declarations) {
        var styleSheet;
        if (document.styleSheets) {
            if (document.styleSheets.length === 0) {
                var styleElement;
                if (document.createElement && (styleElement =
                    document.createElement('style'))) {
                    styleElement.type = 'text/css';
                    document.getElementsByTagName('head')[0].appendChild(styleElement);
                    styleSheet = styleElement.sheet;
                }
            }
            if (document.styleSheets.length > 0) {
                styleSheet = document.styleSheets[document.styleSheets.length - 1];
                if (styleSheet.insertRule) {
                    styleSheet.insertRule(
                        selectorText + ' { ' + declarations + ' }',
                        styleSheet.cssRules.length
                    );
                } else if (styleSheet.addRule) {
                    styleSheet.addRule(selectorText, declarations);
                }
            }
        }
    }

    //hide success stories if we have javascript///
    addCSSRule ( '#success_stories table', 'display:none;' );
    
    function setCookie ( c_name, value, expiredays ) {
        var exdate = new Date ();
        exdate.setDate ( exdate.getDate () + expiredays );
        document.cookie = c_name + "=" + escape( value )+ ( ( expiredays == null ) ? "" : ";expires="+exdate.toGMTString () );
    }
    
    function getCookie ( c_name ) {
        if ( document.cookie.length > 0 ) {
            c_start=document.cookie.indexOf ( c_name + "=" );
            if ( c_start != -1 ) { 
                c_start = c_start + c_name.length + 1; 
                c_end = document.cookie.indexOf ( ";", c_start );
                if ( c_end == -1 ) c_end = document.cookie.length;
                return unescape ( document.cookie.substring ( c_start, c_end ) );
            } 
        }
        return "";
    }
    
    function success_stories(){
        function tpl_exec ( tpl, vars ) {
            for (var k in vars ) tpl = tpl.replace ( '%'+k+'%', vars[k] )
            return tpl;
        };
        var
            stories = [
                {
                    name: 'Lily Wong',
                    desc: 'Australian Awards for Teaching Excellence finalist, VU lecturer',
                    url: 'http://www.vu.edu.au/About_VU/Marketing_and_Communications/Success_Stories/Lily_Wong/indexdl_89382.aspx',
                    img: 'http://www.vu.edu.au/library/scripts/objectifyMedia.aspx?file=images/584/14.jpg&siteID=4&str_title=Lily Wong',
                    alt: 'Australian Awards for Teaching Excellence finalist, VU lecturer'
                },
                {
                    name: 'Lily Stojanovska',
                    desc: 'Associate Professor, winner Barbara Gross Award, Who\'s Who of Australian Women',
                    url: 'http://www.vu.edu.au/About_VU/Marketing_and_Communications/Success_Stories/Lily_Stojanovska/indexdl_88634.aspx',
                    img: 'http://www.vu.edu.au/library/scripts/objectifyMedia.aspx?file=images/584/12.jpg&siteID=4&str_title=Lily Stojanovska',
                    alt: 'Associate Professor, winner Barbara Gross Award, Who\'s Who of Australian Women'
                },
                {
                    name: 'Simon Garlick',
                    desc: 'Former AFL player, Manager Customer Relations with LeasePlan Australia, and member of Western Bulldogs Football Club Board of Directors',
                    url: 'http://www.vu.edu.au/About_VU/Marketing_and_Communications/Success_Stories/Simon_Garlick/indexdl_88353.aspx',
                    img: 'http://www.vu.edu.au/library/scripts/objectifyMedia.aspx?file=images/584/16.jpg&siteID=4&str_title=Simon Garlick',
                    alt: 'Former AFL player, Manager Customer Relations with LeasePlan Australia, and member of Western Bulldogs Football Club Board of Directors'
                },
                {
                    name: 'Mark O\'Rourke',
                    desc: 'School of School of Creative Industries program manager, Fullbright Academic Professional Award winner',
                    url: 'http://www.vu.edu.au/About_VU/Marketing_and_Communications/Success_Stories/Mark_ORourke/indexdl_88037.aspx',
                    img: 'http://www.vu.edu.au/library/scripts/objectifyMedia.aspx?file=images/584/15.jpg&siteID=4&str_title=Mark O\'Rourke',
                    alt: 'School of School of Creative Industries program manager, Fullbright Academic Professional Award winner'
                } ],
            tpl = '<a style="text-decoration:none;" href="/public_html/testonly/Courses%20-%20Victoria%20University%20-%20A%20New%20School%20of%20Thought_files/%25url%25"><img src="/public_html/testonly/Courses%20-%20Victoria%20University%20-%20A%20New%20School%20of%20Thought_files/%25img%25" width="105" alt="%alt%" style="border:0; float: left;" /><img src="/public_html/testonly/Courses%20-%20Victoria%20University%20-%20A%20New%20School%20of%20Thought_files/library/scripts/objectifyMedia.aspx?file=images/564/10.gif&siteID=4&str_title=HPSuccessStories.gif" width="127" height="65" alt="Read more VU Success Stories" style="border:0;" /> <h5 style="text-decoration:none;font-size:12px; margin-left:110px;">%name%</h5> <p style="text-decoration:none;margin-left:110px;">%desc%</p></a> <p style="clear:left;margin-left:110px;"><a href="http://www.vu.edu.au/About_VU/Marketing_and_Communications/Success_Stories/index.aspx">More success stories »</a></p>',
            success_count = getCookie ( 'success_count' ),
            success_num = success_count == 0 ?
                new_num ( success_num, stories.length - 1 ) :
                getCookie ( 'success_num' ),
            story = stories[success_num];
            
        if ( ++ success_count == 4 ) success_count = 0;
        setCookie ( 'success_count', success_count );
        setCookie ( 'success_num', success_num );
        document.getElementById ( 'success_stories' ).innerHTML = tpl_exec ( tpl, story );
        
    };
    function new_num ( old_num, max ) {
        var newnum = Math.floor ( Math.random () * max + 1 );
        return newnum == old_num ? new_num ( old_num, max ) : newnum;
    }
    addEvent(window, 'load', success_stories);
} ) ();
