var loop = 1;

var loop_id = 1; 

var videoFile = 'videoFile';

var player;

var randomnumber = 0;

var pin_title_info = 1;

var current_genre_id = 0;

var current_title_id = 0;


function toggle_visibility(id) {

   var e = document.getElementById(id);

	  if(e.style.display == 'block')

		 e.style.display = 'none';

	  else

		 e.style.display = 'block';

}





function title_get_alpha_data(letter, id) {

	$("#"+id).load("service/DataService.aspx?action=letter_menu&letter="+letter); 

}



function title_get_data(id, title_id) {

	if (pin_title_info == 1 ) {
    
	var e = document.getElementById(id+"_data");

	if (e.innerHTML == 1) {

		$.get("service/DataService.aspx?action=title_menu&title_id="+title_id,

		  function(data) { 

		  	e.innerHTML = data;
		  	

		  	Cufon.replace('#title_data_'+title_id);

		  	toggle_visibility(id);

		});

	} else 

		toggle_visibility(id);

    }
}


function title_reset_classes(new_id) { 

	for (var i = 0; i < 5; i++ )

		$("#five_titles_"+i).removeClass('active');



	$("#five_titles_"+new_id).addClass('active');

}



function title_select_main(title_id) {

	loop = 0;

	$("#main_title_img").fadeOut("slow");

	title_reset_classes(title_id);

	setTimeout("title_load_content("+title_id+")", 500);

}



function title_select_main_cycle(title_id) {

	if (loop == 1) {

		$("#main_title_img").fadeOut("slow");

    	title_reset_classes(title_id);

		setTimeout("title_load_content("+title_id+")", 500);

	}

}



function title_load_content(title_id) {

	$.get("service/DataService.aspx?action=title_get_image&title_id="+title_id,

		   function(data) { 

				var e = document.getElementById("main_title_img"); 

			 	e.innerHTML = data;

			 	$("#main_title_img").fadeIn("slow");

			});



	$.get("service/DataService.aspx?action=title_get_text&title_id="+title_id,

		  function(data) { 

		  	var e = document.getElementById("main_title_text"); 

		  	e.innerHTML = data;

		  	Cufon.replace('#homePano h1');

			});

	

	$("#main_title_link").load("service/DataService.aspx?action=title_get_link&title_id="+title_id);

	

	// flash

	$.get("service/DataService.aspx?action=title_get_trailer&title_id="+title_id,

		  function(data) { 

            
		  	videoFile = data;	
		  	

		  });

	

}



function title_cycle_through_five() {

    if (loop_id>=5) {

		loop_id = 0;

    }



    if (loop == 1) 	{ 

        setTimeout("title_select_main_cycle("+loop_id+")", 4000);

		loop_id = loop_id + 1;

		setTimeout("title_cycle_through_five()", 9000);

    }

}



function title_write_swf_object(video_file) {

	  var so = new SWFObject('swf/player.swf','mpl','940','510','9');
        
	  videoFile = video_file;

	  randomnumber = Math.floor(Math.random()*100000);

	  so.addParam('allowfullscreen','true');

	  so.addParam('allowscriptaccess','always');

	  so.addParam('wmode','opaque');

	  so.addVariable('backcolor','000000');

	  so.addVariable('frontcolor','000000');

	  so.addVariable('lightcolor','cc9900');

	  so.addVariable('screencolor','000000');

	  so.addVariable('skin','swf/beelden.zip');

	  so.addVariable('controlbar','over');

	  so.addVariable('autostart','true');

	  so.write('mediaspace');

	  player = document.getElementById('mpl');

}

function title_write_video_object(video_file) {
	    
	    videoFile = video_file;
	    	    
	    jwplayer("mediaspace").setup({
	        autostart: true,
	        flashplayer: "/swf/player.swf",
	        file: videoFile,
	        height: 510,
	        width: 940,
	        skin: "/swf/beelden.zip",
	        backcolor: "000000",
	        frontcolor: "000000",
	        screencolor: "000000"
	    });
	    
}

function title_pass_video_object(video_file) {
	
	videoFile = video_file;
	
}


function hideMainNav() {

	$("#main_title_h1").fadeOut("slow");

	$("#mainFilmControls").fadeOut("slow");

	$("#mainNav").fadeOut("slow");

	$("#mainNav_menu").fadeIn("slow");

}



function showMainNav() {

	$("#main_title_h1").fadeIn("fast");

	$("#mainFilmControls").fadeIn("fast");

	$("#mainNav").fadeIn("fast");

	$("#mainNav_menu").fadeOut("fast");

}



var menu = 1;

function set_menu_var(value) {

	menu = value;

}



function check_menu() {

	if (menu==0) {
		toggle_visibility('mainNav');
		$('#navSearchContainer').css("display", "none");
		$('#menuTab').css('display', 'block');
		
	} else {
		setTimeout('check_menu()', 1000);
	}
}
	
function search_submit(event) {
    
    
	if (event.keyCode == 13) {
		get_search_result();	
		
	}
	
}

function get_search_result() { 

    
	var searchstring = $("#searchstring").val();
	$.get("service/DataService.aspx?action=search_get_data&searchstring="+searchstring,
	    
		  function(data){
		  
				var e = document.getElementById("search_result");
				
				e.innerHTML = data;
				//$('#navSearchContainer').css('display', 'block'); 
				show_navigation('search');
		  });
		  
}


function getIEVersionNumber() {
    var ua = navigator.userAgent;
    var MSIEOffset = ua.indexOf("MSIE ");
    
    if (MSIEOffset == -1) {
        return 10;
    } else {
        return parseFloat(ua.substring(MSIEOffset + 5, ua.indexOf(";", MSIEOffset)));
    }
}


function reset_navigation() {

	//setTimeout('reset_navigation_do()', 500);
	if (cat_on == 0) {
		$('#navCatalogContainer').css("display", 'none');
		reset_navigation_do();
		fully_reset = 1;
	}

}



function reset_navigation_do() {

	if ($("#navCatalogContainer").css("display")!='block') {

		reset_genre();

		reset_title();

	}

}



function reset_genre() {

	if (current_genre_id != 0) { $('#'+current_genre_id).css("display", "none"); current_genre_id = 0; }

}



function reset_title() {

	if (current_title_id != 0) { $('#'+current_title_id).css("display", "none"); current_title_id = 0; }

}



function clicked_genre(id) {

    
    
	if (id != current_genre_id) {
        
		reset_genre();

		current_genre_id = id;

		$("#"+id).css("display", "block");

	}

}



function clicked_title(id, title_id) {

	if (id != current_title_id) { 

		reset_title();

		current_title_id = id;

		title_get_data(id, title_id);

	}

}

function show_navigation(id) {
	if (id=='nav') {
		reset_navigation();
		$('#navSearchContainer').css('display', 'none'); 
		$('#navLoginContainer').css('display', 'none'); 
		$('#navCatalogContainer').css('display', 'block');
	} else if (id=='login') {
		$('#navSearchContainer').css('display', 'none'); 
		$('#navLoginContainer').css('display', 'block'); 
		$('#navCatalogContainer').css('display', 'none');
	} else if (id=='search') {
		$('#navSearchContainer').css('display', 'block'); 
		$('#navLoginContainer').css('display', 'none'); 
		$('#navCatalogContainer').css('display', 'none');
	}
}


var cat_on = 0;
var reset_on = 1;
var fully_reset = 1;
function show_catalog() {
      if (cat_on == 0 && reset_on == 1 && fully_reset == 1) {
    	  $('#navSearchContainer').css('display', 'none');
    	  $('#navCatalogContainer').css('display', 'block');
      }
      cat_on =  1;
      reset_on = 0;
      fully_reset = 0;
}
 
function hide_catalog() {
      cat_on       = 0;
      reset_on = 0;
      setTimeout(function(){
            if (cat_on==0) {
                  reset_on = 1;
                  reset_navigation();
            }
      }, 100);
     
}







