var flash_element;
var blogbody;
var isFF = false
var hasFlash = false

$(document).ready(function () {
	if (FlashDetect.installed) {
		hasFlash = true
		onFlash();
	}
	/*else {
		onHTML();	
	}*/
});


function onFlash(){ 
	if (navigator.userAgent.indexOf("Firefox")!=-1) {
		isFF = true;	
	}
	flashembed("flash", {src:"4krs.swf", id:"4krs_flash", expressInstall:"expressInstall.swf" },{
			//flashvars
			movie_title:getQueryVariable('movie_title'),
			movie_play:getQueryVariable('movie_play')
	});
	flash_element = document.getElementById("4krs_flash");
	$("#blog").hide();
	
	//$(".back_to_flash").click(close_blog);
	
	if (getQueryVariable('news') == 'true' || getQueryVariable('news') == 'yes' || getQueryVariable('news') == '1'){
		open_blog();
	}
}

function open_blog(){
	$("#flash").animate({ height:"0px" },500);
	$("#blog").slideDown(500, overflow_visible); // callback overflow visible
	if (isFF){
		setTimeout('destroy_flash();',500);
	}
};	

function close_blog(){
	if (isFF && hasFlash) {		
		flashembed("flash", {src:"4krs.swf", id:"4krs_flash", expressInstall:"expressInstall.swf" },{/*fvars*/});
		flash_element = document.getElementById("4krs_flash");
	}
	setTimeout('close_blog_to();',100)	
}

function destroy_flash(){
	if (hasFlash) {
		document.getElementById('flash').innerHTML = '';
	}
}

function close_blog_to(){
	overflow_hidden();
	$("#blog").slideUp(500);
	$("#flash").animate({ height:"100%" },500);
	if (!isFF && hasFlash){ 
		flash_element.highFPS();
	}
}

function overflow_visible(){
	if (blogbody != null) {
		$(blogbody).css({"overflow":"visible"});
	}
};

function overflow_hidden(){
	if (blogbody != null) {
		$(blogbody).css({"overflow":"hidden"});
	}
};


/*function rip_from_frame () {
	//alert('fefe');
  var i = document.getElementById('4krs_blog');
  if (i.contentDocument) {
    var d = i.contentDocument;
  } else if (i.contentWindow) {
    var d = i.contentWindow.document;
  } else {
    var d = window.frames['4krs_blog'].document;
  }
  // x is target on send page -- 
  blogbody = d.getElementById('blogbody');
  // alert(x.innerHTML);
  //blogbody = x
  return false;     
}*/

//get variables from url
function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
	} 
}

function checkIfInFrame() {
	alert(window.location.search.substring(1));
}

// ---------------------
// IF NO FLASH INSTALLED

function onHTML() {
	//nothing actually
}


		