/***********************************************/
/*   Initialisation script                     */
/***********************************************/
// return jQuery reference back after other scripts
var $ = jQuery.noConflict();
var palette = new Array();
palette[0] = ["default","#dedede"];
palette[1] = ["yellow","#FFCC33"];
palette[2] = ["lightyellow","#ffffcc"];
palette[3] = ["green","#99cc33"];
palette[4] = ["lightgreen","#e3f0c8"];
palette[5] = ["blue","#003366"];
palette[6] = ["lightblue","#99ccff"];

function lookupValue(arr,index) {
	var c = 0;
	for (var i=0; i < arr.length; i ++) {
		if(index == arr[i][0]) { c = i; break; }
	}
	return arr[c][1];
}

// panel state control vars
//var currPanel = 1;

$(document).ready(function()
    {
	$(".cve_panel").wrapInner("<div class=\"left_top\"><div class=\"right_top\"><div class=\"left_bot\"><div class=\"right_bot\"><div class=\"content\"></div></div></div></div></div></div>");
	$("#cve_registration_form :input").each(function() {
		var color_class_1 = $("#cve_registration_form div").attr('class'); color_class_1 = color_class_1.substring(color_class_1.lastIndexOf(' ')+1,color_class_1.length);
		$(this).bind("change",function(e) {
			$(this).removeClass("error-" + color_class_1);
		});
	});
	$("#cve_login_form :input").each(function() {
		var color_class_2 = $("#cve_login_form div").attr('class'); color_class_2 = color_class_2.substring(color_class_2.lastIndexOf(' ')+1,color_class_2.length);
		$(this).bind("change",function(e) {
			$(this).removeClass("error-" + color_class_2);
		});
	});
//


	// CVE button
	$('#cve_clickthru').hover(function(){
		$(".rollover", this).stop().animate({top:'65px'},{queue:false,duration:300});
	}, function() {
		$(".rollover", this).stop().animate({top:'147px'},{queue:false,duration:300});
	});


    }
);


// Homepage Random Image
var imageFolder = Math.floor(Math.random()*8)+1;


// UCD Main Menu Dropdown - Click On & Roll Off
/*
sfHover = function() {
	if(typeof(document.getElementById("nav_dropdown")x) == 'object') {
	    var sfEl = document.getElementById("nav_dropdown").getElementsByTagName("LI")[0];
	    sfEl.onclick=function () {
	        this.className+=" sfhover";
	    }
	    sfEl.onmouseout=function(e) {
	        if (!e) var e = window.event;
	        var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
	        if ( reltg.parentNode.parentNode.id == 'nav2_dropdown') return;
	        this.className='';
	    }
	}
}
if (window.addEventListener) window.addEventListener('load', sfHover, false);
else if (window.attachEvent ) window.attachEvent("onload", sfHover);
*/


// Connect Login Scripts
var userpwdFocus = false;
function hadFocus(set)
{
    if (set) userpwdFocus = true;
    return userpwdFocus;
}



function login()
{
    document.cplogin.user.value=document.userid.user.value;
    document.cplogin.submit();
}






/***********************************************/
/*   RMS Scripts                               */
/***********************************************/


function ShowLayer(whichLayer)
{
    if (document.getElementById)
    {
        // this is the way the standards work
        var style2 = document.getElementById(whichLayer).style;
        style2.display = "block";
    }
    else if (document.all)
    {
        // this is the way old msie versions work
        var style2 = document.all[whichLayer].style;
        style2.display = "block";
    }
    else if (document.layers)
    {
        // this is the way nn4 works
        var style2 = document.layers[whichLayer].style;
        style2.display = "block";
    }
}

function HideLayer(whichLayer)
{
    if (document.getElementById)
    {
        // this is the way the standards work
        var style2 = document.getElementById(whichLayer).style;
        style2.display = "none";
    }
    else if (document.all)
    {
        // this is the way old msie versions work
        var style2 = document.all[whichLayer].style;
        style2.display = "none";
    }
    else if (document.layers)
    {
        // this is the way nn4 works
        var style2 = document.layers[whichLayer].style;
        style2.display = "none";
    }
}


/***********************************************/
/*   Previously Embedded Scripts               */
/***********************************************/

function MM_preloadImages() { //v3.0
    var d=document; if(d.images){
        if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
            if (a[i].indexOf("#")!=0){
                d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];
            }
    }
}

function MM_swapImgRestore() { //v3.0
    var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
    var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
    }
    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
    if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
    var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
        if ((x=MM_findObj(a[i]))!=null){
            document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];
        }
}

var all_zmiana = 3;
var var_zmiana = (all_zmiana - 1);
var cos=0; // initialise to non-zero value
var plus=new Array();
plus[1] =0;
plus[2] =0;
plus[3] =0;
var var_arrow=1;

// LCD-EDIT 06/08/2010 15:40
var sectionNameRoot = 'cve'; // update to new images conformant to convention ('teaching'|'cve')
var pathRoot = '../wp-includes/images/';
//var pathRoot = 'http://www.ors.ie/wp-includes/images/';
var fileExt = "gif";
var paneWidth = 474; //474
var offSet = 440;

function change(id) {
	var close_img = './' + pathRoot + '/' + sectionNameRoot + '_sect_' + cos + '_' + 'close' + '.' + fileExt;
	var open_img = './' + pathRoot + '/' + sectionNameRoot + '_sect_' + id + '_' + 'open' + '.' + fileExt;
	//var paneWidth = (id == 1) ? 474 : 474;
	if(cos != id) {
		$("#cell_"+cos).animate({width: "-=" + offSet}, 500);
		$("#cell_"+cos).css('background', 'url(' + close_img + ') left top no-repeat');
		cos = id;
		$("#cell_"+id).animate({width: "+=" + offSet}, 500);
		$("#cell_"+cos).css('background', 'url(' + open_img + ') left top no-repeat');
	} else {
		change(1);
	}
}



function change_arrow(id, co, img) {
	var sectionNameRoot = 'teaching';
    if(co == 0) {
        if(var_arrow != id) {
            img.src = './' + pathRoot + '/' + sectionNameRoot + '_arrow_' + id + '_off.jpg';
        }
    }else{
        img.src = './' + pathRoot + '/' + sectionNameRoot + '_arrow_' + id + '_on.jpg';
    }
}

function home_arrow(id, img) {
	var sectionNameRoot = 'teaching';
	for(var i=1; i<=3; i++) {
		if( i == id) {
			img.src = './' + pathRoot + '/' + sectionNameRoot + '_arrow_' + i + '_on.jpg';
			$("#h"+i+"1").css('display', 'block');
			$("#h"+i+"2").css('display', 'block');
			var_arrow = id;
		}else{
			document.getElementById('no_' + i).src = './' + pathRoot + '/' + sectionNameRoot + '_arrow_' + i + '_off.jpg';
			$("#h"+i+"1").css('display', 'none');
			$("#h"+i+"2").css('display', 'none');
		}
	}
}

function plus_minus(id) {
	var sectionNameRoot = 'teaching';
    if(plus[id] == 0){
        $("#plus_minus_"+id).css('background', 'url(./' + pathRoot + '/' + sectionNameRoot + '_plus_on.jpg) left top no-repeat');
    }else{
        $("#plus_minus_"+id).css('background', 'url(./' + pathRoot + '/' + sectionNameRoot + '_minus_on.jpg) left top no-repeat');
    }
}

function plus_minus_out(id) {
	var sectionNameRoot = 'teaching';
    if(plus[id] == 0){
        $("#plus_minus_"+id).css('background', 'url(./' + pathRoot + '/' + sectionNameRoot + '_plus.jpg) left top no-repeat');
    }else{
        $("#plus_minus_"+id).css('background', 'url(./' + pathRoot + '/' + sectionNameRoot + '_minus.jpg) left top no-repeat');
    }
}

function plus_minus_click(id) {
	var sectionNameRoot = 'teaching';
    if(plus[id] == 0){
        plus[id] = 1;
    }else{
        plus[id] = 0;
    }
    if(plus[id] == 0){
        $("#plus_minus_"+id).css('background', 'url(./' + pathRoot + '/' + sectionNameRoot + '_plus_on.jpg) left top no-repeat');
        if(navigator.userAgent.substring(25,31) == "MSIE 6") {
            $("#plus_more_"+id).css('overflow', 'hidden');
            $("#plus_more_"+id).css('display', 'block');
            $("#plus_more_"+id).css('height', '5px');
        }
    }else{
        $("#plus_minus_"+id).css('background', 'url(./' + pathRoot + '/' + sectionNameRoot + '_minus_on.jpg) left top no-repeat');
        if(navigator.userAgent.substring(25,31) == "MSIE 6") {
            $("#plus_more_"+id).css('overflow', 'hidden');
            $("#plus_more_"+id).css('display', 'block');
            $("#plus_more_"+id).css('height', 'auto');
        }
    }
    if(navigator.userAgent.substring(25,31) != "MSIE 6") {
        $("#plus_more_"+id).slideToggle("slow");
    }
}



/* Replaced to fix IE issue */

function arrow(id) {
	for(var i=1; i<=6; i++) {
		if( i == id) {
			$("#res_text_"+i).css('display', 'inline');
            $("#res_nav_" + i + "").addClass('res_nav_' + i + '_on');
			if(i == 1) {
				$("#pro_nav_"+i).addClass('pro_nav_1_on');
			}else{
				$("#pro_nav_"+i).addClass('pro_nav_all_on');
			}
			$("#hide_list_"+i+"_1").css('display', 'block');
			$("#hide_list_"+i+"_2").css('display', 'block');
			$("#hide_img_"+i).css('display', 'block');
			$("#hide_text_"+i).css('display', 'inline');
			$("#hide_text_"+i+"_table").css('display', 'inline');
		}else{
			$("#res_text_"+i).css('display', 'none');
            $("#res_nav_" + i + "").removeClass('res_nav_' + i + '_on');
			if(i == 1) {
				$("#pro_nav_"+i).removeClass('pro_nav_1_on');
			}else{
				$("#pro_nav_"+i).removeClass('pro_nav_all_on');
			}
			$("#hide_list_"+i+"_1").css('display', 'none');
			$("#hide_list_"+i+"_2").css('display', 'none');
			$("#hide_img_"+i).css('display', 'none');
			$("#hide_text_"+i).css('display', 'none');
			$("#hide_text_"+i+"_table").css('display', 'none');
		}
	}
}


function box(id, co) {
	var sectionNameRoot = 'teaching';
    if(co == 1) {
        $("#pro_box"+id).css('background', 'transparent url(./' + pathRoot + '/' + sectionNameRoot + '_box_bg_on.jpg) left top no-repeat');
    }else{
        $("#pro_box"+id).css('background', 'transparent url(./' + pathRoot + '/' + sectionNameRoot + '_box_bg_off.jpg) left top no-repeat');
    }
}

/*
setTimeout('change(1)',    1);
setTimeout('change(2)', 2000);
setTimeout('change(3)', 4000);
setTimeout('change(4)', 6000);
setTimeout('change(5)', 8000);
setTimeout('change(1)', 10000);
*/

// LCD-EDIT 06/08/2010 15:40
//setTimeout('change(1)',    1); // do not kick off change event with a timeout - on document ready
//change(1);
//zmiana();
//show_foto();

if(navigator.userAgent.substring(25,31) == "MSIE 6") {
    for(var id=1 ; id < 3 ; id++){
        $("#plus_more_"+id).css('overflow', 'hidden');
        $("#plus_more_"+id).css('display', 'block');
        $("#plus_more_"+id).css('height', '5px');
        $("#more_img_"+id).css('padding-top', '5px');
        $("#more_text_"+id).css('padding-top', '5px');
    }
}

function aca_show(id) {
	$('#aca_btn_hide_' + id).css('display', 'block');
	$('#aca_btn_show_' + id).css('display', 'none');
	var new_height = document.getElementById('academic_box_' + id).scrollHeight;
	$('#academic_box_' + id).animate({height: new_height + 'px'}, 500);
}

function aca_hide(id) {
	$('#aca_btn_hide_' + id).css('display', 'none');
	$('#aca_btn_show_' + id).css('display', 'block');
	$('#academic_box_' + id).animate({height: '18px'}, 500);
}

function zmiana(){
	hide_foto();
	setTimeout('show_foto()', 1000);
	setTimeout('zmiana()', 6000);
}

function show_foto() {
	var_zmiana = ((var_zmiana+1)%all_zmiana);
	$('#wel_img_' + var_zmiana).fadeIn("slow");
}

function hide_foto() {
	$('.wel_img').fadeOut("slow");
}


var play_sel = 0;
var play_all = 3; // How many profiles in video section
var cast_sel = 0;
var cast_all = 3; // How many profiles in showcast section

function change_text(id) {
	$("#sca_title_0").css('display', 'none');
	$("#sca_title_1").css('display', 'none');
	$("#sca_title_2").css('display', 'none');
	$("#sca_title_" + id).css('display', 'block');
	$("#sca_ul_0").css('display', 'none');
	$("#sca_ul_1").css('display', 'none');
	$("#sca_ul_2").css('display', 'none');
	$("#sca_ul_" + id).css('display', 'block');
}

function change_nav(id, img) {
	if(id == 1) {
		$("#sca_btn_1_1").css('display', 'none');
		$("#sca_btn_1_2").css('display', 'block');
		$("#sca_btn_2_1").css('display', 'block');
		$("#sca_btn_2_2").css('display', 'none');
		$(".sca_show2").css('display', 'block');
		$(".sca_cast2").css('display', 'none');
	}
	if(id == 2) {
		$("#sca_btn_1_1").css('display', 'block');
		$("#sca_btn_1_2").css('display', 'none');
		$("#sca_btn_2_1").css('display', 'none');
		$("#sca_btn_2_2").css('display', 'block');
		$(".sca_show2").css('display', 'none');
		$(".sca_cast2").css('display', 'block');
	}
}

function change_play(id) {
	if(id == 0){
		if(play_sel < (play_all - 1)){
			play_sel += 1;
		}
	}else{
		if(play_sel > 0){
			play_sel -= 1;
		}
	}
	$(".sca_show3").animate({left: '-' + (287 * play_sel) + 'px'}, 700);
}

function change_cast(id) {
	if(id == 0){
		if(cast_sel < (cast_all - 1)){
			cast_sel += 1;
		}
	}else{
		if(cast_sel > 0){
			cast_sel -= 1;
		}
	}
	$(".sca_cast3").animate({left: '-' + (287 * cast_sel) + 'px'}, 700);
}



