// JavaScript Document

var current_format_id = 0;

function flexpos(){
	$("#scroll_area").height( $(window).height()-$("#main_content").position().top - $("#main_footer").height() );

	setBackgroundColor();

}

function win_size(){
	var winsize = {};
	var total_screen_pixels=   window.screen.availWidth * window.screen.availHeight;
	
	if (navigator.appName=="Netscape") {
		winsize.width = window.innerWidth;
		winsize.height = window.innerHeight;
	}
	if (navigator.appName.indexOf("Microsoft")!=-1) {
		winsize.width = document.body.offsetWidth;
		winsize.height = document.body.offsetHeight;
		winsize.area = winsize.width * winsize.height;
	}
	
	if ( total_screen_pixels > 0 ){
		winsize.area = winsize.width * winsize.height;
		winsize.prop = winsize.area / total_screen_pixels;
	}
	
	return winsize;
}

function setBackgroundColor(){
	var winsize = win_size();
	var dark= ( winsize.prop - 0.3 ) * 1.1;
	if (dark < 0.0) dark= 0.0;
	if (dark > 1.0) dark= 1.0;
	document.body.bgColor = rgb( 255 * dark, 255 * dark , 255 * dark );
}

function hswap( ){
	var number= Math.ceil( Math.random() * 4 );
	$( "#headerimage" ).attr( "src" , "./template/images/header_logo_"+number+".jpg" );
}

function bswap( id, state ){
	if ( mainmenu=="" ) { mainmenu= id; } 
	
	var ext= "_pink.gif";
	if ( state == 1 ) ext= "_high.gif";
	if ( id == mainmenu ) ext= "_gray.gif";
	$( "#"+id ).attr( "src" , "./template/images/"+id+ext );
}

function bhdrswap( id, state ){
	
	var ext= ".gif";
	if ( state == 1 ) ext= "_high.gif"; 
	$( "#"+id ).attr( "src" , "./template/images/"+id+ext );
}


function bnozoom(){
		$("#bigoverlay").hide(0);
		$("#bigoverlay").css( "width", "10px" );
		$("#bigoverlay").css( "height", "10px" );
		$("#bigoverlay").css( "top", "0px" );
		$("#bigoverlay").css( "left", "0px" );
		$("#bigoverlay").attr( "innerHTML", "" );

}
function bzoom( name , id ){
	$("#bigoverlay").show(0);
	$("#bigoverlay").css( "top", "0px" );
	$("#bigoverlay").css( "left", "0px" );
	$("#bigoverlay").css( "width", "640px" );
	$("#bigoverlay").css( "height", "500px" );
	$("#bigoverlay").hide(0);
	
	img='<a href="#" onclick="bnozoom();" onmouseout="bnozoom();"><img src="'+ name + '" border="0"></a>';
	$("#bigoverlay").attr( "innerHTML", img );

	var s=  $("#contentscroller").scrollTop() + $("#"+id ).position().top +216;	
	if ( s < 216 ) s= 216;
	$("#bigoverlay").css( "top",  s + "px" );
	$("#bigoverlay").css( "left", $(window).width() /2 - 250 + "px" );
	$("#bigoverlay").show(200);

}

function breveal( id ){
	$("#" + id ).hide(200);
	$("#" + id + "_meer" ).show(200);
}

function bhide( id ){
	$("#" + id ).show(200);
	$("#" + id + "_meer" ).hide(200);
}

function bshowall(){
	$(".select_public").parent(0).show(0);
	$(".select_conselec").parent(0).show(0);
	$(".select_profeq").parent(0).show(0);
	$(".select_public").parent(0).show(0);
	$(".select_mobility").parent(0).show(0);
	$(".select_home").parent(0).show(0);
	$(".select_fmcg").parent(0).show(0);
	$(".select_food").parent(0).show(0);
	$(".select_news").parent(0).show(0);
}

function bscroll( id ){
	bshowall();
	var s=  $("#scroll_area").scrollTop() + $("#top"+id ).position().top + 16;	
	$('#scroll_area').scrollTo( {top:s+'px', left:'0px'}, 800 );
}

function nscroll( id ){
	bshowall();
	var s=  $("#scroll_area").scrollTop() + $("#item"+id ).position().top ;	
	$('#scroll_area').scrollTo( {top:s+'px', left:'0px'}, 800 );
}

function bfilter( id ){
	
	if ( currentfilter == "" ) $("#block_welcome").hide(250);

	if ( current_format_id == 1 ){
		bload_thumb_format( id );
		return;
	}


	if ( " brand printed packaging online av".indexOf( id ) > 0 ){ 
		
		if ( id != 'brand' ) 		$(".select_brand").parent(0).parent(0).hide(0);
		if ( id != 'printed' ) 		$(".select_printed").parent(0).parent(0).hide(0);
		if ( id != 'packaging' ) 	$(".select_packaging").parent(0).parent(0).hide(0);
		if ( id != 'online' ) 		$(".select_online").parent(0).parent(0).hide(0);
		if ( id != 'av' ) 			$(".select_av").parent(0).parent(0).hide(0);
		if ( id != 'news' ) 		$(".select_news").parent(0).hide(0);
		
		$(".select_"+id).parent(0).parent(0).show(0);
		
		currentfilter= id;
		return;
	}

	if ( id == currentfilter ){ 	
		bshowall( ); 
		currentfilter="-"; 
		return;  
	}

	if ( id != 'public' ) 	$(".select_public").parent(0).hide(0);
	if ( id != 'conselec' ) $(".select_conselec").parent(0).hide(0);
	if ( id != 'profeq' ) 	$(".select_profeq").parent(0).hide(0);
	if ( id != 'medical' ) 	$(".select_medical").parent(0).hide(0);
	if ( id != 'mobility' ) $(".select_mobility").parent(0).hide(0);
	if ( id != 'home' ) 	$(".select_home").parent(0).hide(0);
	if ( id != 'fmcg' ) 	$(".select_fmcg").parent(0).hide(0);
	if ( id != 'food' ) 	$(".select_food").parent(0).hide(0);
	if ( id != 'news' ) 	$(".select_news").parent(0).hide(0);
	
	$(".select_"+id).parent(0).show(0);

	currentfilter= id;
}

function show_case( dbid ){
	document.location= "cases.php?id="+dbid;
}

function load_case( dbid ){
	$loading= "<table width='640'><tr><td align='center'><br><br><img src='include/loading20.gif'></td></tr></table>"; 
	$("#content_double").attr("innerHTML", $loading ); 
	$.post("include/ajax.casecontent.php",{ id: dbid },
		function(html) { fillCasecontent( html ); }
	);
}
function fillCasecontent( html ){
	$("#content_double").attr("innerHTML", html ); 
}

function bload_thumb_format( id ){
	$loading= "<table width='540'><tr><td align='center'><br><br><img src='include/loading20.gif'></td></tr></table>"; 
	
	$("#databasewrap").attr("innerHTML", $loading ); 
	$("#block_welcome").hide(500);
	
	$.post("include/ajax.recontent.php",{ type: "inc.items_thumb.html", fill: id },
		function( html ) { fillRecontent( html ); }
	);
	
}

function  bload_format( id ){
	var formatname= Array( "inc.items.html", "inc.items_thumb.html"  );
	
	current_format_id= id;
	
	$loading= "<table width='540'><tr><td align='center'><br><br><img src='include/loading20.gif'></td></tr></table>"; 
	
	$("#databasewrap").attr("innerHTML", $loading ); 
	$("#block_welcome").hide(500);
	
	$.post("include/ajax.recontent.php",{ type: formatname[ id ], fill: "all" },
		function( html ) { fillRecontent( html ); }
	);
}
function fillRecontent( html ){
	$("#databasewrap").attr("innerHTML", html ); 
}

function rgb(R,G,B)  { return "#" + toHex(R)+toHex(G)+toHex(B); }

function toHex(N) {
 if (N==null) return "00";
 N=parseInt(N); if (N==0 || isNaN(N)) return "00";
 N=Math.max(0,N); N=Math.min(N,255); N=Math.round(N);
 return "0123456789ABCDEF".charAt((N-N%16)/16)
      + "0123456789ABCDEF".charAt(N%16);
}


