﻿function pop_file(f, w, h) {
	var temp_url = f;
	var new_win = window.open(temp_url, 'pop' + h + w, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=' + w + ',height=' + h + ',alwaysRaised=yes');
	new_win.focus();
}

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);
		EventCache.add(elm, evType, fn);
		return r;
	} else {
		elm['on' + evType] = fn;
	}
}

function check_search_form(opt) {
	form = document.search_form;
	el = '';
	if (form.SearchTerm.value == '') {
		alert('Please enter a term to search on and then click "GO" again. \n \n' + el);
		if (opt == 1) return false;
	} else {
		if (opt == 1) {
			return true;
		} else {
			form.submit();
		}
	}
}

var old_port_id = 0;
function highlight_port_item(pid) {
	if (document.getElementById('PortItem' + pid)) {
		if (old_port_id > 0) {
			document.getElementById('PortItem' + old_port_id).className = 'NotActivePortfolioItem';
		}
		old_port_id = pid;
		document.getElementById('PortItem' + pid).className = 'ActivePortfolioItem';
	}
}

function choose_port_item(pageid, pid) {
	try {
		xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
	} catch (e1) {
		try {
			xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
		} catch (e2) {
			xmlhttp = null;
		}
	}
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	if (xmlhttp && document.getElementById('PortfolioImage')) {
		document.getElementById('PortfolioImage').innerHTML = '<table cellpadding="0" cellspacing="0" border="0" width="540"><tr><td><img src="/images/1x1trans.gif" width="1" height="480" border="0" alt="" /></td><td align="center"><img src="/images/other/ajax_loader.gif" width="32" height="32" border="0" alt="" /></td><td><img src="/images/1x1trans.gif" width="1" height="480" border="0" alt="" /></td></tr></table>';
		highlight_port_item(pid);
		var qs = '?PageID=' + pageid + '&Opt=1&ID=' + pid;
		xmlhttp.open('GET', '/includes/portfolio_load.aspx' + qs, true);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.statusText == 'OK') {
					document.getElementById('PortfolioImage').innerHTML = xmlhttp.responseText;
				}
			}
		};
		xmlhttp.send(null);

		// update number links at the bottom
		try {
			xmlhttp2 = new ActiveXObject('Msxml2.XMLHTTP');
		} catch (e1) {
			try {
				xmlhttp2 = new ActiveXObject('Microsoft.XMLHTTP');
			} catch (e2) {
				xmlhttp2 = null;
			}
		}
		if (!xmlhttp2 && typeof XMLHttpRequest != 'undefined') {
			xmlhttp2 = new XMLHttpRequest();
		}
		if (xmlhttp2 && document.getElementById('PortfolioCounter')) {
			var qs = '?PageID=' + pageid + '&Opt=2&ID=' + pid;
			xmlhttp2.open('GET', '/includes/portfolio_load.aspx' + qs, true);
			xmlhttp2.onreadystatechange = function() {
				if (xmlhttp2.readyState == 4) {
					if (xmlhttp2.statusText == 'OK') {
						document.getElementById('PortfolioCounter').innerHTML = xmlhttp2.responseText;
					}
				}
			};
			xmlhttp2.send(null);
		}
	} else {
		document.location = '/portfolio.aspx?PageID=' + pageid + '&ID=' + pid;
	}
}

// code for scrolling announcement settings
var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline = 0;
var rotation_time = 7000; //time in milliseconds
var animation_time = 2000; //time in milliseconds

$(document).ready(function(){
	headline_count = $("div.scrolling_headline").size();
	current_headline = 0;
	var h1=$("#scrolling_headline"+current_headline).height();
	var h2=$("#scrollup").height();
	h=Math.round((h2-h1)/2.3);
	$("#scrolling_headline"+current_headline).show().animate({top: h},2000);
	if (headline_count>1) headline_interval = setInterval(headline_rotate,rotation_time);
	old_headline = current_headline;
});

function headline_rotate() {
	current_headline = (old_headline + 1) % headline_count
	var h2=$("#scrollup").height();
	var h1=$("#scrolling_headline"+current_headline).height();
	var h3=$("#scrolling_headline"+old_headline).height();
	$("#scrolling_headline"+old_headline).animate({top: -h3},2000, function() {
    	$(this).css('top', h2+'px');
    });
	h=Math.round((h2-h1)/2.3);
	$("#scrolling_headline"+current_headline).show().animate({top: h},2000);
	old_headline = current_headline;
}
