function checkIeVersion(){
	var version = 999; // we assume a sane browser
    if (navigator.appVersion.indexOf("MSIE") != -1){
      // bah, IE again, lets downgrade version number
      version = parseFloat(navigator.appVersion.split("MSIE")[1]);
	}
    if (version<7){	
		var info = "Browser version: "+ version + "\n";
		info += "Da biste ispravno pregledali sajt potreban je internet explorer 7 ! \n";
		info += "Da li zelite da preuzmete Internet Explorer 7 ?";
		conf = confirm(info);
		if (conf){
		  location.href = "http://www.microsoft.com/windows/downloads/ie/getitnow.mspx";  
		}else
		{
		  history.go(-1);
		}		  
	}	
}
/*	header_height - okvir gore
	content1_height - flash header
	content2_height - flash content
	footer_height - okvir dole
*/
var header_height = 18;
var content1_height = 0;
var content2_height = 606+164;
var footer_height = 18;
var temp_name = "home";
var flashLinks=path+"links-home.swf";
var flashContent=path+"Flash-"+language+"home.swf";

//jqury variable pageName (becouse of imposisble to pass parameters on callback function)
var pageName = "";
function callPage(name){		

	//alert("Page name: "+name+".");
	
	// swich language on site by replacing path to swf directory
  if(name=="eng"){		
		path="swf/ENG/"
 		language = "";			
		name = temp_name;
		flashLinks=path+"links-home.swf";		
		flashContent=path+"Flash-"+language+name+".swf";
		
		// call function that call this function 2 time (links and content)
		swich_language(name);		
		
	}else if (name=="cg"){
    	path="swf/CG/";
		language = "cg_";		
		name = temp_name;
		flashLinks=path+"links-home.swf";		
		flashContent=path+"Flash-"+language+name+".swf";
		
		// call function that call this function 2 time (links and content)
		swich_language(name);		
	}
	else{	
		//	check if popup is pressed
		if(name=="cijene"){
			var str="pdf/accommodation_price_list_www.pdf";
			var  strTarget = "windowNew";
			openPDF(str,strTarget)		  
		}else if (name=="rezervacije"){
		  popitup('reservation/reservation.php', 'Rezervacije', 415, 497);		
		}else if (name=="kontakt"){
		  popitup('kontakt/kontakt.html', 'Kontakt', 496, 316);		
		}else{
		  
		  flashLinks=path+"links-home.swf";		
		  flashContent=path+"Flash-"+language+name+".swf";	
		 
		  //alert(flashContent);
		 // var hash = "pages/"+name+".html";		
		  var hash = "pages/home.html";		
		  hash = hash.replace(/^.*#/, '');
		  // moves to a new page. 
		  // pageload is called at once. 
		 // $.historyLoad(hash);	
		 load_ajax();
		  temp_name=name;
      }
	}	
	return false;
}

function load_ajax(){
	$("div#content-flash").load("pages/home.html");	
}

function swich_language(name){	
	//callPage(name);
	load_ajax();
}

function ajax_load_flash(page){
	pageName = page;
	//load_content();
	//$("div#content-flash").hide("slow",load_content);		
	
} 

function load_content(){
	//callPageHistory("pages/"+pageName+".html");
	callPageHistory("pages/home.html");
//	$("div#content-flash").load("pages/"+pageName+".html", show_content);
}

function show_content(){	   
	$("div#content-flash").show("slow");
}

// fucntion called from flash and XHTML
function popup(name){

    var fullName = '#popup'+name;  
    //centering with css  
    centerPopup(fullName);  
    //load popup  
    loadPopup(fullName);     
}

function popitup(url,name,width,height) {

	newwindow=window.open(url,name,'width='+width+','+'height='+height);        

    //Center new window	
    var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;

    var popupWidth = width;
    var popupHeight = height;
    var top = windowHeight/2-popupHeight/2;
	var left = windowWidth/2-popupWidth/2;       

    //document.documentElement.scrollLeft/Top.
    newwindow.moveTo(left, top);

	if (window.focus) {newwindow.focus()}

	return false;
}       

function thisMovie(movieName) {

      if (navigator.appName.indexOf("Microsoft") != -1) {
          return window[movieName];
      }
      else {
          return document[movieName];
      }
} 

function fixHeights() {    
	/* set values defined in js above	*/
	
	//gornji okvir
    $('#cosak-gl').height(header_height);
	$('#okvir-go').height(header_height);
	$('#cosak-dg').height(header_height);
	
	//flash header
	$('#okvir-le').height(content1_height);
	$('#header-flash').height(content1_height);
	$('#okvir-de').height(content1_height);
	
	//flash content
	resize_flash_content();
	
	//donji okvir
	$('#cosak-ld').height(footer_height);
	$('#okvir-do').height(footer_height);
	$('#cosak-dd').height(footer_height);
	//alert ("fix");
}

function resize_flash_content(){	
	$('#okvir-le-content').height(content2_height);
	$('#content-flash').height(content2_height);
	$('#okvir-de-content').height(content2_height);
}

// PageLoad function
// This function is called when:
// 1. after calling $.historyInit();
// 2. after calling $.historyLoad();
// 3. after pushing "Go Back" button of a browser
function pageload(hash) {
	// hash doesn't contain the first # character.
	if(hash) {
		// restore ajax loaded state
		$("#content-flash").load(hash);
	} else {
		// start page
		$("#content-flash").empty();
	}
}

$(document).ready(function(){
	// Initialize history plugin.
	// The callback is called at once by present location.hash. 
	//$.historyInit(pageload);		
	
	callPage("home");
	fixHeights();		
});

checkIeVersion();

//open FactSheets PDF documents in 5 language
function FactSheets(language){  
  
  var str="";
  var  strTarget = "windowNew";
  
  switch(language)
  {
  case "english":
    str = "FactSheets/Fact_Sheets_CG_Eng.pdf";      
    break;    
  case "france":    
    str = "FactSheets/Fact_Sheets_CG_Fra.pdf";
    break;
  case "german":    
    str = "FactSheets/Fact_Sheets_CG_Deu.pdf";
    break;    
  case "italian":    
    str = "FactSheets/Fact_Sheets_CG_Ita.pdf";
    break;
  case "russian":    
    str = "FactSheets/Fact_Sheets_CG_Rus.pdf";
    break;   
  }
  openPDF(str,strTarget)
}
function openPDF(_str,_strTarget){
	//open PDF in new windows and move to location 0.0 1002:750
   mywindow = window.open(_str,_strTarget,'toolbar=no,location=no,status=yes,menubar=no,scrollba rs=yes,resizable=yes,width=1002,height=720');
   mywindow.moveTo(0,0);
   //web function
   //<a href="javascript:void(0)" onClick="window.open('Manual.pdf','windowNew','toolbar=no,location=no,status=yes,menubar=no,scrollba rs=yes,resizable=yes,width=800,height=600');">pdf</a>
}
function popup(name)
{
    var fullName = '#popup'+name;
	
    //centering with css  
    centerPopup(fullName);  
    //load popup  
    loadPopup(fullName);      
}
