﻿/*
JSTarget function by Roger Johansson, www.456bereastreet.com
*/
var JSTarget = {
	init: function(att,val,warning) {
		if (document.getElementById && document.createElement && document.appendChild) {
			var strAtt = ((typeof att == 'undefined') || (att == null)) ? 'class' : att;
			var strVal = ((typeof val == 'undefined') || (val == null)) ? 'non-html' : val;
			var strWarning = ((typeof warning == 'undefined') || (warning == null)) ? ' (opens in a new window)' : warning;
			var oWarning;
			var arrLinks = document.getElementsByTagName('a');
			var oLink;
			var oRegExp = new RegExp("(^|\\s)" + strVal + "(\\s|$)");
			for (var i = 0; i < arrLinks.length; i++) {
				oLink = arrLinks[i];				
				if (strVal == 'popup')
				{
				    if((oRegExp.test(oLink.getAttribute(strAtt))))
				    {
				        oLink.onclick = JSTarget.popupWin;
				    }
				}
				else
				{				
				    if ((strAtt == 'class') && (oRegExp.test(oLink.className)) || (oRegExp.test(oLink.getAttribute(strAtt)))) {
					    oWarning = document.createElement("em");
					    oWarning.appendChild(document.createTextNode(strWarning));
					    oLink.appendChild(oWarning);
					    oLink.onclick = JSTarget.openWin;
				    }
				}

			}
			oWarning = null;
		}
	},
	openWin: function(e) {
		var event = (!e) ? window.event : e;
		if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) return true;
		else {		        
		    var oWin = window.open(this.getAttribute('href'), '_blank');
			if (oWin) {
				if (oWin.focus) oWin.focus();
				return false;
			}
			oWin = null;
			return true;
		}
	},
	popupWin: function(e) {
        var features = 'location=0,statusbar=0,menubar=0,resizable=1,scrollbars=1,width=640,height=520';	
 
        	
		var event = (!e) ? window.event : e;
		if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) return true;
		else {		    
		    var oWin = window.open(this.getAttribute('href'), '_blank', features);
			if (oWin) {
				if (oWin.focus) oWin.focus();
				return false;
			}
			oWin = null;
			return true;
		}	},
	/*
	addEvent function from http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html
	*/
	addEvent: function(obj, type, fn) {
		if (obj.addEventListener)
			obj.addEventListener(type, fn, false);
		else if (obj.attachEvent) {
			obj["e"+type+fn] = fn;
			obj[type+fn] = function() {obj["e"+type+fn]( window.event );}
			obj.attachEvent("on"+type, obj[type+fn]);
		}
	}
};



JSTarget.addEvent(window, 'load', function(){JSTarget.init("rel","external","");});
JSTarget.addEvent(window, 'load', function(){JSTarget.init("rel","popup","");});

$(document).ready(function() {
	$('.slideshow-1').cycle({
		fx: 'fade',
		timeout: 4000,
		speed: 500
	});	

	setTimeout(
		function() {
			$('.slideshow-2').cycle({
				fx: 'fade',
				timeout: 4000,
				speed: 500
			});
	}, 2000);

	$('.slideshow').cycle({
		fx: 'fade',
		timeout: 4000,
		speed: 500
	});
	
    $('#news-ticker ol').cycle({
		fx: 'fade',
		speed: 500,
		easing: 'swing',
		timeout: 6000,
		pause: 1,
		prev: '#news-ticker ul li.prev a',
		next: '#news-ticker ul li.next a',
		fastOnEvent: 500
	});
	
	var pause = true;
	$('#news-ticker ul li:first-child a').click(
		function() {
			if (pause == true) {
				$('#news-ticker ol').cycle('pause');
				$(this).parent().removeClass("pause").addClass("resume");
				pause = false;
			} else {
				$('#news-ticker ol').cycle('resume');
				$(this).parent().removeClass("resume").addClass("pause");
				pause = true;
			}
		}
	);
	
	$('#news-ticker ol li').ellipsis();
	
	var col1Capacity = $("body.news #mainContent ol li").length - Math.floor($("body.news #mainContent ol li").length/2) - 1;
	$("body.news #mainContent ol:eq(1)").append($("body.news #mainContent ol:eq(0) li:gt(" + col1Capacity + ")"));	
});


