$(function(){	
	var panels = $('img[id^=imgpanel]');
	$(panels)
		.mouseover(function(){
			$(this)
				.stop(true,true)
				.siblings()
					.css('opacity','0')
					.end()
				.animate({'opacity':'1'},'fast');
		})
		.mouseout(function(){
			$(this).animate({'opacity':'0'},'fast');
		})
		.eq(0)
			.animate({'opacity':'1'},'fast',function(){
				$(panels).eq(1).animate({'opacity':'1'},'fast',function(){
					$(panels).eq(2).animate({'opacity':'1'},'fast',function(){
						$(panels).eq(3).animate({'opacity':'1'},'fast',function(){
							$(panels).animate({'opacity':'0'});
						});
					});
				});
			});
	$('input.standardTextbox')
		.focus(function(){
			$(this).css('borderColor','#27429B')
		}).blur(function(){
			$(this).css('borderColor','#A7A6AA')
		});
});

var mouseLoc = "";

//function for mouseover events

function mouseOver(menuItem){
	mouseLoc = menuItem;
	if (mouseLoc == 'sec_services'){		
		$('#div_services').css({visibility:'visible'});
	}
	else if (mouseLoc == 'security_tech'){		
		$('#div_technology').css({visibility:'visible'});
	}
	else if (mouseLoc == 'training'){
		$('#div_schedule').css({visibility:'visible'});
	}
	else if (mouseLoc == 'media_center'){
		$('#div_media').css({visibility:'visible'});
	}
	switch (menuItem){
		case 'sec_services':
		case 'security_tech':
		case 'training':
		case 'employment':
		case 'franchise':
		case 'media_center':		
			$('#'+menuItem).css({background:"url('/images/triangle.gif') no-repeat left"});
			break;
		case 'contact':
			$('#'+menuItem).css({background:"url('/images/triangle.gif') no-repeat top left"});
		default:
			break;
	} 
} 

function mouseOut(menuItem){
	if (menuItem == "sec_services"){
		if (mouseLoc != "div_services"){			
			$('#div_services').css({visibility:'hidden'});
			$('#'+menuItem).css({background:''});
		}
		else {
			mouseLoc = '';
		}		
	}
	else if (menuItem == "security_tech"){
		if (mouseLoc != "div_technology"){
			$('#div_technology').css({visibility:'hidden'});
			$('#'+menuItem).css({background:''});
		}
		else {
			mouseLoc = '';
		}		
	}
	else if (menuItem == "training"){
		if (mouseLoc != "div_schedule"){
			$('#div_schedule').css({visibility:'hidden'});
			$('#'+menuItem).css({background:''});
		}
		else {
			mouseLoc = '';
		}
	}
	else if (menuItem == "media_center") {
	    if (mouseLoc != "div_media") {
	        $('#div_media').css({visibility:'hidden'});
			$('#'+menuItem).css({background:''});
	    }
	    else {
	        mouseLoc = '';
	    }
	}
	else {
		$('#'+menuItem).css({background:''});
	}
}

function boxHover(hover, boxID){
	if (hover) {		
		$('#'+boxID).css({background:"url('/images/triangle.gif') no-repeat left"});
	}
	else {
		$('#'+boxID).css({background:''});
	}
}

function formFocus(id){	
	$("#"+id).css({borderColor:'#27429B'});
}

function formBlur(id){	
	$("#"+id).css({borderColor:'#A7A6AA'});
}

function positionitnow(elem) {    
    var ypos = document.body.scrollTop;
    if (ypos == 0)
    {
        if (window.pageYOffset) {
            ypos = window.pageYOffset;
        }
        else {
            ypos = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;        
       }               
    }    
    $("#"+elem).css({top:ypos + "px"});
}

function initShortDesc(control) {
  $(this).focus(function(){
    var len = $(this).val().length;
    $('span#counter').val((255 - len) + ' character(s) remaining');
  });
}

// Png fix companion script

function update_srcs() {
    var allImages = document.getElementsByTagName("img");
    for (i = 0; i < allImages.length; i++) {
        if (allImages[i].style.visibility != "visible") {            
            allImages[i].style.visibility = "visible";
        }
    }
}

// iFrame functions for wordpress

function setIframeHeight() {
    parent.document.getElementById('wordpress').height = document['body'].offsetHeight;
}

function loadIframeSRC(page, cat_id, post_id) {    
    var result;
    var def = false;
    switch (page) {
        case 'home': result = '/media/wordpress'; break;
        case 'video': case 'print': case 'online': result = '/media/wordpress/?cat=' + cat_id; break;
        default: result = '/media/wordpress'; def = true;
    }
    if (post_id) {
        if (def) {          
          result += "?p=" + post_id.toString();
        } else {
          result += "&p=" + post_id.toString();
        }
    }
    document.getElementById('wordpress').src = result;
}

// error handling

function get_location(idOfControlToTag, divToPosition, divToPositionBackground, divToPositionColor, orientationVertical, orientationHorizontal, fixedWidth, offsetLeft) {
    var width = 0;
    var height = 0;
    var top = 0;
    var left = 0;
    var getAttributes = null;        
    document.getElementById("hdnDivToClose").value = divToPosition;
    if (document.getElementById(idOfControlToTag)) {
        getAttributes = $("#" + idOfControlToTag);
    } else {
        alert("Control to tag not found:" + idOfControlToTag);
        return false;
    }
    if (!(document.getElementById(divToPosition))) {
        alert("Div to position not found");
        return false;
    }    
    var pos = getAttributes.position();    
    if (fixedWidth) {
        width = fixedWidth;
    } else {
        width = document.getElementById(idOfControlToTag).offsetWidth;
    }
    height = document.getElementById(idOfControlToTag).offsetHeight;
    top = pos.top;
    if (offsetLeft) {        
        left = pos.left + offsetLeft;
    } else {
        left = pos.left;
    }
    set_position(width, height, top, left, divToPosition, divToPositionBackground, divToPositionColor, orientationVertical, orientationHorizontal, idOfControlToTag);
}

function set_position(w, h, t, l, d, bgColor, fgColor, orientVertical, orientHorizontal, setsFocus) {
    var container = document.getElementById(d);
    container.style.width = w + "px";
    if (orientHorizontal == "left") {
        container.style.left = (l - w) + "px";
    }
    if (orientHorizontal == "center") {
        container.style.left = l + "px";
    } else {
        if (orientVertical == "below") {
            t = t - h;
        } else {
            t = t + h;
        }
    }
    if (orientHorizontal == "right") {
        container.style.left = (l + w) + "px";
    }
    if (orientVertical == "below") {
        container.style.top = (t + h) + "px";
    }
    container.style.position = "absolute";
    container.style.zIndex = "100";
    container.style.backgroundColor = bgColor;
    container.style.color = fgColor;
    container.style.visibility = "hidden";
    container.style.display = "";
    if (orientVertical == "above") {
        container.style.top = (t - container.offsetHeight) + "px";
    }
    container.style.display = "none"
    container.style.visibility = "visible";
    fade_in(d, setsFocus);
}

function fade_in(divToAnimate, setsFocus) {    
    $("#" + divToAnimate).slideDown(500), function() {
        set_focus(setsFocus);
    }    
}

function set_focus(id) {
    $('#' + id).focus();
}

function hide_message() {
    if (document.getElementById("hdnDivToClose")) {
        if (document.getElementById("hdnDivToClose").value) {
            var id = document.getElementById("hdnDivToClose").value
            if (document.getElementById(id)) {
                document.getElementById(id).style.display = "none";
            }
        }
    }
}

// update viewstate

function update_viewstate() {
    __theFormPostData = '';
    __theFormPostCollection = new Array();
    WebForm_InitCallback();
}