/**Start of the index page price feed**/
var default_box=1;
$(document).ready(function(){
	$('.arrow_left').mouseover(function(){
		if(default_box!=1){								
			$('#rate_left').attr('src','images/pricefeed_back_over.gif');
		}else{
			$('#rate_left').attr('src','images/pricefeed_back_disable.gif');
		}		
    }).mouseout(function(){
		if(default_box!=1){								
			$('#rate_left').attr('src','images/pricefeed_back.gif');
		}else{
			$('#rate_left').attr('src','images/pricefeed_back_disable.gif');
		}   	
    });

	$('.arrow_right').mouseover(function(){
		if(default_box!=4){
			$('#rate_right').attr('src','images/pricefeed_next_over.gif');
		}else{
			$('#rate_right').attr('src','images/pricefeed_next_disable.gif');
		}		
    }).mouseout(function(){
		if(default_box!=4){
			$('#rate_right').attr('src','images/pricefeed_next.gif');
		}else{
			$('#rate_right').attr('src','images/pricefeed_next_disable.gif');
		}
    });
	
	$('.right_button').mouseover(function(){
		var tt=$(this).find("img").attr('src');
		tt=tt.replace('button1','button2');
		var t=$(this).find("img").attr('src',tt);
    }).mouseout(function(){
		var tt=$(this).find("img").attr('src');
		tt=tt.replace('button2','button1');
		var t=$(this).find("img").attr('src',tt);
    });
	//Commentary javascript
	//CLOSING POPUP 
	//Click the x event!
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
	
	/****Ticker hover ****/
	$('#ticker').hover(
      function () {
        cps=0;
      }, 
      function () {
        cps=tSpeed;
      }
    );

});
var ratebox_content = new Array(5);

ratebox_content[4]='Other CFDs ';
ratebox_content[1]='Forex CFD 1';
ratebox_content[2]='Forex CFD 2';
ratebox_content[3]='Forex CFD 3';

function switch_ratebox(status){
	switch(status)
	{
		case "up":
			$('.CFD'+default_box.toString()).hide();
			if(default_box==1){
				$('#rate_left').attr('src','images/pricefeed_back.gif');
			}if(default_box==3)
			{
				$('#rate_right').attr('src','images/pricefeed_next_disable.gif');
			}
			default_box++;
			$('.CFD'+default_box.toString()).show();
			$('.ratebox_content').text(ratebox_content[default_box]);
			break;
		case "down":
			$('.CFD'+default_box.toString()).hide();
			if(default_box==4){
				$('#rate_right').attr('src','images/pricefeed_next.gif');
			}else if(default_box==2)
			{
				$('#rate_left').attr('src','images/pricefeed_back_disable.gif');
			}
			default_box--;
			$('.CFD'+default_box.toString()).show();
			$('.ratebox_content').text(ratebox_content[default_box]);
			break;
		case "initial":
			$('.CFD1').show();
			default_box=1;
			$('.ratebox_content').text(ratebox_content[default_box]);
			break;
		default:
			break;
	}
	if(default_box==1)
	{
		$('#rate_left').attr('disabled','disabled');
	}else if(default_box==4)
	{
		$('#rate_right').attr('disabled','disabled');
	}else
	{
		$('#rate_left').attr('disabled','');
		$('#rate_right').attr('disabled','');
	}
	
}	
/**End of the index page price feed**/
/**Start Center content Javascript**/
var current_tab='tab-1';
var current_tab_id='0';

function switch_tab(tab_name,tabid)
{
	$('#'+current_tab).hide();
	$('#tab li:eq('+current_tab_id+') a').removeClass('tab_selected');
	$('#'+tab_name).show();
	$('#tab li:eq('+tabid+') a').addClass('tab_selected');
	current_tab = tab_name;
	current_tab_id=tabid;
}
function ini_tab()
{
	$('#tab-1').show();	
	
}

/**End Center content Javascript**/

/* START TICKER CODE - RISK WARNING TICKER */

var tWidth='100%';                   // width (in pixels)
var tHeight='14px';                  // height (in pixels)
var tcolour='#e0dfdf';               // background colour:
var moStop=false;                    // pause on mouseover (true or false)
var fontfamily = 'tahoma';           // font for content
var tSpeed=1;                        // scroll speed (1 = slow, 5 = fast)

// enter your ticker content here (use \/ and \' in place of / and ' respectively)
var content='Bacera International does not accept clients from the United States.  Bacera International\'s services are not intended for distribution to, or use by, any person in any country or jurisdiction where such distribution or use would be contrary to local law or regulation.  It is the responsibility of the customer to ascertain the terms of and comply with any local law or regulation to which they are subject.';

// Simple Marquee / Ticker Script
// copyright 3rd January 2006, Stephen Chapman
// permission to use this Javascript on your web page is granted
// provided that all of the below code in this script (including this
// comment) is used without any alteration
var cps=tSpeed; 
var aw, mq; 
var fsz = parseInt(tHeight) - 3; 

function startticker(){
	
	if (document.getElementById) {
		var tick = '<div style="position:relative;width:'+tWidth+';height:'+tHeight+';overflow:hidden;background-color:'+tcolour+'"'; 
		
		if (moStop) tick += ' onmouseover="cps=0" onmouseout="cps=tSpeed"'; 
		
		tick +='><div id="mq" style="position:absolute;left:0px;top:0px;font-family:'+fontfamily+';font-size:'+fsz+'px;white-space:nowrap;"><\/div><\/div>'; 
		document.getElementById('ticker').innerHTML = tick; 
		mq = document.getElementById("mq"); 
		mq.style.left=(parseInt(tWidth)+600)+"px"; 
		mq.innerHTML='<span id="tx">'+content+'<\/span>'; 
		aw = document.getElementById("tx").offsetWidth;
		lefttime=setInterval("scrollticker()",50);
	}
} 

function scrollticker(){
	mq.style.left = (parseInt(mq.style.left)>(-100 - aw)) ?parseInt(mq.style.left)-cps+"px" : parseInt(tWidth)+600+"px";
} 
  
/* END TICKER CODE - RISK WARNING TICKER */

var tooltip=function(){
	var id = 'tt';
	var top = 3;
	var left = 3;
	var maxw = 300;
	var speed = 10;
	var timer = 20;
	var endalpha = 95;
	var alpha = 0;
	var tt,t,c,b,h;
	var ie = document.all ? true : false;
	return{
		show:function(v,w){
			if(tt == null){
				tt = document.createElement('div');
				tt.setAttribute('id',id);
				t = document.createElement('div');
				t.setAttribute('id',id + 'top');
				c = document.createElement('div');
				c.setAttribute('id',id + 'cont');
				b = document.createElement('div');
				b.setAttribute('id',id + 'bot');
				tt.appendChild(t);
				tt.appendChild(c);
				tt.appendChild(b);
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				document.onmousemove = this.pos;
			}
			tt.style.display = 'block';
			c.innerHTML = v;
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie){
				t.style.display = 'none';
				b.style.display = 'none';
				tt.style.width = tt.offsetWidth;
				t.style.display = 'block';
				b.style.display = 'block';
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
		},
		pos:function(e){
			var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
			var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
			tt.style.top = (u - h) + 'px';
			tt.style.left = (l + left) + 'px';
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function(){
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
		}
	};
}();


/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/
//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");

}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		$('#popupContact').text('');
		
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

function popup_verify()
{
	//centering with css
	centerPopup();
	$('#popupContact').load("commentary_content.php");
	//load popup
	loadPopup();
	return false;
}
/*********************************************************************/