var minWidth = 964; //COLOCAR LARGURA MÍNIMA DO FLASH PARA IE6
var minHeight = 768; // COLOCAR ALTURA MÍNIMA DO FLASH PARA IE6


$(document).ready(function() {
	$('#faqLink').click(function() {
		openWindow('http://kraft.neoassist.com/?th=trakinas', 700, 795);
		return false;
	});
	
	if(notSupMaxPropert()) { //ie6
		flashMinMsieProperties();
	}
	
	$("a[rel*=external]").attr("target", "_blank");
	
	$.openWindow = function(url, width, height, title) {
		if (url === undefined) {
			return false;
		} else if (url.constructor === Object) {
			var options = $.extend(
				{},
				$.openWindow.defaults,
				url
			);
		} else {
			var options = $.extend(
				{},
				$.openWindow.defaults,
				{ 'url': url, 'width': width, 'height': height, 'title': title }
			);
		};
	
		if (options.dialog === null) {
			options.dialog = $('<div id="dialog" title="Trakinas"></div>').appendTo('body');
		};
		
		options.dialog.dialog({
			'width': options.width,
			'height': options.height,
			'modal': true,
			'autoOpen': false,
			'closeOnEscape': false,
			'open': function() {
				if ($.isFunction(options.events.open)) {
					options.events.open();
				}
			},
			'close': function() {
				if ($.isFunction(options.events.close)) {
					options.events.close();
				}
			}
		});
		options.dialog.html('<iframe width="600" height="550" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="'+options.url+'"></iframe>')
		options.dialog.dialog('open');
		return false;
	}
	$.extend(
		$.openWindow,
		{
			defaults: {
				'height': 580, //635
				'width': 630, //640
				'title': 'Trakinas',
				'events': {
					'open': function() {
						/*
						$('#dialog iframe').contents().find('.close').live('click', function() {
							$('#dialog').dialog('close');
    						return false;
						});
						*/
					},
					'close': function() {
						refreshUserData()
					}
				},
				'dialog': null
			}
		}
	);
	
});



function openWindowMinigame(url, width, height) {
	window.open(url,'TrakinasPopup','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=' + width + ',height=' + height);
}

function openWindow(url, width, height) {
	window.open(url,'TrakinasPopup','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=' + width + ',height=' + height);
}

function tamanduaWindow(url) {
    var hsize, wsize;var width = screen.width;var height = screen.height;
    if(height <= 800){hsize = height-150;}
    else{hsize = 720;}
    wsize = parseInt((((hsize*100)/720)/100)*486);
    
    window.open(url,'TrakinasPopup','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,directories=no,titlebar=no,resizable=no,top=0px,left=0px,width=' + wsize + ',height=' + hsize);
}

function thisMovie(movieName) {
	 if (navigator.appName.indexOf("Microsoft") != -1) {
		 return window[movieName];
	 } else {
		 return document[movieName];
	 }
 }
function refreshUserData() {
	 thisMovie("plugin-flash").refreshUserData();
}

/* +window resize */
$(window).resize(
	function(){
		if(notSupMaxPropert()) {
			flashMinMsieProperties();
		}
	}
);
/* * end window resize  */

/* +ie hacks */
function flashMinMsieProperties() {
	var tWindow = $(window); // a janela do browser = this window
	
	if(tWindow.width() <= minWidth) { 		
		$('html, body, #wrapper').css("width", minWidth + "px");
	}
	else {
		$('html, body, #wrapper').css("width","100%");
	}
	if(tWindow.height() <= minHeight) { 
		$('html, body, #wrapper').css("height", minHeight + "px");
	}
	else {
		$('html, body, #wrapper').css("height","100%");
	}
}

function notSupMaxPropert() { // não suporta CSS max properties
	if (typeof document.body.style.maxHeight === "undefined") return true;
	else return false;
}
/* end ie hacks */
