﻿// wires up privacy popups
addLoadEvent(initLicPops);

// opens up privacy windows
function licWindow(link)
{
	var url = link.getAttribute('href');
	var theWin = window.open(url, 'privacy', 'scrollbars=yes,resizable=yes,width=350,height=420');
	if (theWin != null)
	{
		theWin.focus();
		return false;
	}
	return true;
}	

// this function finds all anchor tags with rel="privacy" and wires up onclick handlers
function initLicPops()
{
	
	if (!document.getElementsByTagName)
	{
		return;
	}
	
	var anchors = document.getElementsByTagName("area");

	for (var i=0; i<anchors.length; i++)
	{
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "privacy"))
		{
			var link = anchor.getAttribute("href");
			anchor.onclick = function () 
			{
				return licWindow(this);
			}
		}
	}
	
	anchors = document.getElementsByTagName("a");

	for (var i=0; i<anchors.length; i++)
	{
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "privacy"))
		{
			var link = anchor.getAttribute("href");
			anchor.onclick = function () 
			{
				return licWindow(this);
			}
		}
	}
	
}

function addLoadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

}



function GetWindowSize(Dim) {

	// Get window/viewport size
	var viewportwidth;
	var viewportheight;
 
	if (typeof parent.window.innerWidth != 'undefined') { // for standard browsers
		viewportwidth = parent.window.innerWidth,
		viewportheight = window.innerHeight
	}
	else if (typeof parent.document.documentElement != 'undefined' && typeof parent.document.documentElement.clientWidth != 'undefined' && parent.document.documentElement.clientWidth != 0) { // for IE6
       viewportwidth = document.documentElement.clientWidth,
       viewportheight = document.documentElement.clientHeight
	}
	else { // for legacy browsers
       viewportwidth = parent.document.getElementsByTagName('body')[0].clientWidth,
       viewportheight = parent.document.getElementsByTagName('body')[0].clientHeight
    }
    
    if (Dim == 0) { // return height
		return viewportheight;
    }
    else { // return width
		return viewportwidth;
    }
    
}


// JQuery JS

$(document).ready(function() {

	var VpSize = GetWindowSize(1);

	if (VpSize <= 1024) {
		$("ul.preview_thumbnails li img").css("max-height","150px");
	}
	
	$("a[rel*=DownloadNow]").fancybox({
		frameWidth: 500, 
		frameHeight: 500
	});

});