function write_flash(filename, w, h, param, transparent) {
	document.write('<object align="middle" type="application/x-shockwave-flash" data="'+filename+'" Width="'+w+'" height="'+h+'">');
	document.write('<param name="movie" value="'+filename+'" />');
	document.write('<param name="FlashVars" value="'+param+'" />');
	if (transparent) {
		document.write('<param name="wmode" value="transparent" />');
	}
	document.write('</object>');
}


function switch_bg_image(obj) {
	$(obj.parentNode).toggleClass('over');
}

function switch_bg(obj, state) {
	if (state == 'over') $(obj.parentNode).css('background','#f2f2f2');
	if (state == 'out') $(obj.parentNode).css('background','none');
}

function get_companies_by_country(cid,lang) {
	$.get(basehref+'data.companies.php', {CID:cid,site_lang:lang}, function(data) {
		$('#companies').html(data);
	});
}



/* generic window opener */
function openwin(uri,title,w,h){
	if(w){wwidth = w;}else{	wwidth = 380;}
	if(h){wheight = h; }else{ wheight = 380;}
	xy = get_top_left(wwidth, wheight);
	wleft = xy[1];
	wtop = xy[0];
	wnd = window.open(uri, title, "width="+wwidth+", height="+wheight+", left="+wleft+", top="+wtop+", toolbar=no, location=no, scrollbars=yes, status=no, menubar=no, resizable=no, directories=no");
}


/* returns the x,y coordinates of the current screen (for multi monitor setup) */
function get_top_left(width, height){
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
	  		winW = window.innerWidth;
	  		winH = window.innerHeight;
	 		winL = window.screenX;
	 		winT = window.screenY;
	 	} else {
	  		winW = document.body.offsetWidth;
	  		winH = document.body.offsetHeight;
	  		winL = window.screenLeft;
	  		winT = window.screenTop;
	 	}
	}
	
	var scroll = 0;
	var l = winL + winW/2 - width/2;
	var t = winT + winH/2 - height/2;
	
	
  	if(screen.width <= width){
  		width=screen.width;
  	}
  	if(screen.height <= height){
  		height=screen.height;
 	 	var t = 0;
  		var scroll = 1;
  	}
	return Array(t,l);
}


function fix_tables() {
	
	var my_table = false;
	
	my_table = document.getElementsByTagName("table");
	
	if (my_table.length > 0) {
		for (i = 0; i < my_table.length; i++) {
			my_table[i].setAttribute("cellspacing", "0");
			my_table[i].setAttribute("cellpadding", "2");
			my_table[i].setAttribute("width", "100%");
			my_table[i].setAttribute("border", "0");
		}
	}
	
}

var scroller;
var scroller_height;
var scroller_item_height = 20;
var scroller_start_pos;
var items;
var heights = Array();


function init_scroller() {
	scroller = $('#scroller');
	scroller_height = parseInt(scroller.height());
	//alert(scroller.height());
	scroller_start_pos = parseInt(scroller.css('top'));
	items = scroller_height / scroller_item_height;
	for (i=0;i<items;i++){
		heights[i] = -(i * scroller_item_height);
	}
	t = setTimeout('scroll()', 4000);
}

function next_item() {
	
	clearTimeout(t);
	do_stop = false;
	
	current_top = parseInt(scroller.css('top'));

	if (current_top > -scroller_height) {
		scroller.css('top',(current_top - 1) + "px");
		current_top = current_top - 1;
	} else {
		scroller.css('top', 0 + "px");
		current_top = 0;
	}
	
	if (heights.in_array(current_top)) {
		do_stop = true;
	}
	
	if (do_stop == true) {
		clearTimeout(next);
	} else {
		next = setTimeout('next_item()', 1);
	}
	
}

function prev_item() {
	
	clearTimeout(t);
	do_stop = false;
	
	current_top = parseInt(scroller.css('top'));
	
	if (current_top < 0) {
		scroller.css('top',(current_top + 1) + "px");
		current_top = current_top + 1;
	} else {
		scroller.css('top', -(scroller_height) + "px");
		current_top = -(scroller_height);
	}
	
	if (heights.in_array(current_top)) {
		do_stop = true;
	}
	
	if (do_stop == true) {
		clearTimeout(prev);
	} else {
		prev = setTimeout('prev_item()', 1);
	}
	
}

function scroll() {
	
	do_pause = false;
	
	current_top = parseInt(scroller.css('top'));

	if (current_top > -scroller_height) {
		scroller.css('top',(current_top - 1) + "px");
		current_top = current_top - 1;
	} else {
		scroller.css('top', scroller_start_pos + "px");
		current_top = 0;
	}
	
	if (heights.in_array(current_top)) {
		do_pause = true;
	}
	
	if (do_pause == true) {
		t = setTimeout('scroll()', 4000)
	} else {
		t = setTimeout('scroll()', 1);
	}
	
}

Array.prototype.in_array = function(p_val) {
	for(var i = 0, l = this.length; i < l; i++) {
		if(this[i] == p_val) {
			return true;
		}
	}
	return false;
}

function fix_tables() {
	
	var my_table = false;
	
	my_table = document.getElementsByTagName("table");
	
	if (my_table.length > 0) {
		for (i = 0; i < my_table.length; i++) {
			my_table[i].setAttribute("cellspacing", "0");
			my_table[i].setAttribute("cellpadding", "2");
			my_table[i].setAttribute("width", "100%");
			my_table[i].setAttribute("border", "0");
		}
	}
	
}


$(document).ready(
	function(){
		if ($('#global_footer').css('display') == 'none') {
			$('a.toggle').css('background-image','url(images/footer_arrow_closed.gif)');
		}	

		$('a.toggle').click(function(){
				
				var obj = $('#global_footer').css('display');
				
				if (obj == 'block') {
					$('#global_footer').css('display','none');
					$('a.toggle').css('background-image','url(images/footer_arrow_closed.gif)');
				} else {
					$('#global_footer').css('display','block');
					$('a.toggle').css('background-image','url(images/footer_arrow_open.gif)');
				}
			});
		// first page news
		
		if ( $('#scroller') != null){
			
			init_scroller();
			
			$('#news_down').click(function() { 
				next_item();
			});
			$('#news_up').click(function() { 
				prev_item();
			});
			
		}
	
	}
	
	
	
);




