/* spec for modal window who opens iframe, hard spec size 
 * See info http://digitarald.de/project/squeezebox/1-1/showcase/iframed/
 * 
 */

function showArticle() {
	$$('hr.concealed').each(function(item) {
		item.setStyle('display', 'block');
	});
	$$('div.concealed').each(function(item) {
		item.setStyles({
			display: 'inline',
			overflow: 'hidden',
			height: '1px'
		});
		sIFR.replace(newsgothicsj, {
			selector: '#canvasRightLeft h1',
			css : [
		       '.sIFR-root { font-size:30px; color:#454545;}'
			]
		});
		var articleFx = new Fx.Tween(item, {
			onComplete: function() {
				item.setStyle('height', 'auto');
			}
		});
		var height = (item.getScrollSize().y - 44) + 'px'; // remove padding height
		articleFx.start('height', '1px', height);
	});
}

function run_reveal() {
	var identifyer='#hid#';
	var buff;
	var arr;
	var atags=document.getElementsByTagName('a');
	var pos;

	for (i=0;i<atags.length;i++) {
		pos = -1;
		try {
			buff = atags[i].getAttribute('href');
			pos = buff.indexOf(identifyer);
		} catch(e) {}

		if (pos>=0) {
			arr = buff.substr(pos+identifyer.length).split(',');
			if (arr.length>1) {
				atags[i].setAttribute('href','mai'+'lto:'+arr[0]+'@'+arr[1]);
				if (arr.length>2) {if (arr[2]=='1') {atags[i].innerHTML = arr[0]+'@'+arr[1];}}
				if (arr.length>3) {if (arr[3]=='1') {atags[i].setAttribute('title',arr[0]+'@'+arr[1]);}}
			}
		}
	}
}

function setCookie(cookieName, cookieValue, exdays) {
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var newValue = escape(cookieValue) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
	document.cookie = cookieName + "=" + newValue;
}

function getCookie(cookieName) {
	var x, y, ARRcookies = document.cookie.split(";");
	for (var i = 0; i < ARRcookies.length; i++) {
		x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
		y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
		x = x.replace(/^\s+|\s+$/g, "");
		if (x == cookieName) {
			return unescape(y);
		}
	}
}

$(document).ready(function () {
	var myElements = $("ul.room-list li");

	myElements.addClass("clickable");

	myElements.bind('click', function (event) {
		window.location = this.getElement("a").href;
	});

	myElements.bind('mouseover', function (event) {
		var aElement = this.getElement("a");
		window.status = aElement.href;
		this.title = aElement.title;
	});

	$(".slider").before($('<ul></ul>').attr('id', 'sliderBullets'));

	$(".slider").easySlider({
		auto: true,
		continuous: true,
		speed: 1000,
		pause: 5000,
		prevId: "prevBtn",
		nextId: "nextBtn",
		numeric: true,
		numericId: "sliderBullets",
		controlsShow: false
	});

	$("#dialog").jqm();

	$("#dialogVideo").jqm({ trigger: ".showVideo", onShow: function (hash) {

		if (hash.t) {

			var trigger = $(hash.t);

			if (trigger.hasClass("showVideo")) {

				var videoLink = $(hash.t).attr("href");

				var videoTemplate = "<object width=\"640\" height=\"390\">" +
							  "<param name=\"movie\" value=\"" + videoLink + "\"></param>" +
							  "<embed src=\"" + videoLink + "\" type=\"application/x-shockwave-flash\" width=\"640\" height=\"390\"></embed>" +
							  "</object>";

				$("#contentVideo").html(videoTemplate);

			}
		}

		hash.w.show();
	}
	});

	var cookieValue = getCookie("sjsa-layer");

	if (cookieValue == undefined || cookieValue.length == 0) {
		$('#dialog').jqmShow();
		setCookie("sjsa-layer", "true", 1);
	}

});

