﻿function queryString(ji) {
	hu = window.location.search.substring(1);
	gy = hu.split("&");
	for (i=0;i<gy.length;i++) {
		ft = gy[i].split("=");
		if (ft[0] == ji) {
			return ft[1];
		}
	}
}

function popup(element) {
	  message = $(element).html();
	  var width = $(window).width();
		var height = $(window).height();
		var dheight = $(document).height();
		var obj = $('<div class="popup"><img src="../Bilder/xmas/popup_close.gif" alt="Stäng" class="close"/><div class="padding">'+message+'</div></div>').css('left', ((width / 2) - 254) + 'px').click(function(e) { var x = e.pageX - this.offsetLeft; var y = e.pageY - this.offsetTop; if (x >= 11 && x <= 18 && y >= 10 && y <= 17) { return true; } return false; });
		obj.find('A').click(function() {window.open($(this).attr('href'));});
		var container = $('<div class="popupoverlay"></div>').css('height', dheight + 'px').click(function() { $(this).fadeOut('fast', function() { $(this).remove(); }); }).append(obj)
		$('BODY').append(container);
		$('.popup .close').click(function() { $('.popupoverlay').fadeOut('fast', function() { $(this).remove(); }); })
		$('.popup').css('top', ((height / 2)  + $(window).scrollTop() - $('.popup').height()/2) + 'px');
}

function flashpopup(src, width, height, params) {
	var wwidth = $(window).width();
	var wheight = $(window).height();
	var dheight = $(document).height();
	var flash = $('<div id="popupflash"><div id="flashreplace"></div></div>').height(height).width(width).css('left', ((wwidth / 2) - width/2) + 'px').css('top', ((wheight / 2)  + $(window).scrollTop() - height/2) + 'px').click(function() {return false;});
	var container = $('<div class="flashpopupoverlay"></div>').css('height', dheight + 'px').click(function() { $(this).fadeOut('fast', function() { $(this).remove(); }); }).append(flash)
	
	$('BODY').append(container);
	
	var img = queryString('img');
	var scaleX = queryString('scaleX');
	var scaleY = queryString('scaleY');
	var x = queryString('x');
	var y = queryString('y');
	var rotation = queryString('rotation');
	var flipped = queryString('flipped');
	var friend = queryString('friend');
	var sender  = queryString('sender');
	
	var flashvars = {
		img: img,
		scaleX: scaleX,
		scaleY: scaleY,
		x: x,
		y: y,
		rotation: rotation,
		flipped: flipped,
		friend: friend,
		sender: sender
	};
	
	if(params != null && params != undefined) {
		flashvars = params;
	}
	var params = {
		wMode: 'transparent'
	};

	
	swfobject.embedSWF(src, 'flashreplace', width, height, '10.0.0', params, flashvars, params, {});
}

function flashpopupclose() {
	$('.flashpopupoverlay').fadeOut('fast', function() { $(this).remove(); }); 
}

$(function() {
	
	if($.browser.msie) {
		$('.popupcopy').click(function() {
			clipboardData.setData("text",$(this).parent().find('TEXTAREA').val());			
		});
	} else {
		$('.popupcopy').hide();
	}
	var show = queryString('show');
	if(show!=undefined && show.length>0) {
		flashpopup('Admin/Sve/Moduler/Skicka julkort/Flash/julkort.swf', 700, 530);
	}
});