// popup
$(function() {
	$('.popup').click(function() {
		window.open(this.href, 'legal_popup', 'height='+600+', left='+(screen.width-467)/2+', location=no, resizable=no, scrollbars=yes, status=no, toolbar=no, top='+(screen.height-600)/2+', width='+467);
		return false;
	});
});

// forward to a friend
$(function() {
	$('#friendForm').hide();
	$('#friendFormBtn a').toggle(
		function() {
			$('#friendFormBtn a').addClass('active');
			$('#friendForm').show();
			dcsMultiTrack('WT.ti', 'Forward to a Friend', 'WT.cg_n', 'Entertainment', 'WT.si_n', 'Tell a Friend', 'WT.si_x', '1');
		}, function() {
			$('#friendFormBtn a').removeClass('active');
			$('#friendForm').hide();
		}
	);
});

// random advertisement
$(function() {
	var random_number = Math.floor(Math.random()*$('.advertisement').size()) + parseFloat(1);
	$('#ad' + random_number).show();
});

// iframe resize
function doIframe(){
	o = document.getElementsByTagName('iframe');
	for(i=0;i<o.length;i++){
		if (/\bautoHeight\b/.test(o[i].className)){
			setHeight(o[i]);
			addEvent(o[i],'load', doIframe);
		}
	}
}

function setHeight(e){
	if(e.contentDocument){
		e.height = e.contentDocument.body.offsetHeight + 50;
	} else {
		e.height = e.contentWindow.document.body.scrollHeight + 40;
	}
}

function addEvent(obj, evType, fn){
	if(obj.addEventListener)
	{
	obj.addEventListener(evType, fn,false);
	return true;
	} else if (obj.attachEvent){
	var r = obj.attachEvent("on"+evType, fn);
	return r;
	} else {
	return false;
	}
}

if(document.getElementById && document.createTextNode){
	addEvent(window,'load', doIframe);	
}