$(document).ready(function() {
  /*$("div#stock-quotes").load("stock-quotes.html");
  
  var refreshId = setInterval(function() {
       $("div#stock-quotes").load("stock-quotes.html");
  }, 3000);*/
  
  /* Permission denied to call method XMLHttpRequest.open Firefox */
  /* Gecko (Firefox) browsers have increased security preventing cross domain scripting, we need to get the xml onto our local domain using asp. Try: http://forums.kayako.com/showthread.php?t=3605 */
  if(document.getElementById("stock") != null) {
  $("div#stock-london").load("/wb/handlers/stockticker.ashx?symbol=LDN");
  $("div#stock-hongkong").load("/wb/handlers/stockticker.ashx?symbol=HKG");
  
  var refreshId = setInterval(function() {
       $("div#stock-london").load("/wb/handlers/stockticker.ashx?symbol=LDN");
  }, 10000);
    var refreshId = setInterval(function() {
       $("div#stock-hongkong").load("/wb/handlers/stockticker.ashx?symbol=HKG");
  }, 10000);
  }
  
  if($('fieldset.awards').length > 0) {
    $('<ul id="mycarousel" class="jcarousel-skin"></ul>').insertBefore('fieldset.awards');
    $('ul#mycarousel').jcarousel({
        size: mycarousel_itemList.length,
        scroll: 1,
        visible: 5,
        itemLoadCallback: {onBeforeAnimation: mycarousel_itemLoadCallback}
    });
  }
  
  if( $('.content-tabbed ul').length > 0 ){
  
  	$('.content-tabbed ul').tabs({selectedClass: 'active'});
  	
  }
  
  if(document.getElementById("promo_2") != null) {
      promos();
  }
  
  if(document.getElementById("regions") != null) {
      regions();
	  subRegions();
  }
  
  newwin_setlinks();
	/**
	* Show / hide content
	*/
	/*$(".hidden").css({ "display": "none" });
	$('a.toggle').click(function() {
		$(this).parent('h2').next('div').toggle();
		return false;
	});*/


	/* Toggle tag cloud */
	$('.related a.list').css('visibility','visible');
    $('.related a.list').toggle(
      function () {
		$('.tagcloud').addClass('toggleCloud');
		$('.tagcloud').removeClass('tagcloud');
		$('.related a.list').html('Cloud')
      },
      function () {
		$('.toggleCloud').addClass('tagcloud');
		$('.toggleCloud').removeClass('toggleCloud');
		$('.related a.list').html('List')
      }
    );

});

var mycarousel_itemList = [
    {url: "../SCB.WB/SCB.WB.Web/assets/images/awards/asialegal2007.gif", title: "Flower1", caption: "Singapore Deal of the Year: Start III, USD 1.5 Billion, Collateralised Loan Obligations", website: "http://www.amazon.co.uk", newwin: true},
    {url: "../SCB.WB/SCB.WB.Web/assets/images/awards/asiamoney2006.gif", title: "Flower2", caption: "Best Transaction Bank in Korea - SC First Bank", website: "", newwin : false},
    {url: "../SCB.WB/SCB.WB.Web/assets/images/awards/asiarisk2006.gif", title: "Flower3", caption: "#2 overall in Asia-Pacific", website: "", newwin : false},
    {url: "../SCB.WB/SCB.WB.Web/assets/images/awards/assetsasia2007.gif", title: "Flower4", caption: "Most Improved International Islamic Bank", website: "", newwin : false},
    {url: "../SCB.WB/SCB.WB.Web/assets/images/awards/dealoftheyear2007.gif", title: "Flower5", caption: "Best Trade Finance Services Internet Bank in Asia", website: "", newwin : false},
    {url: "../SCB.WB/SCB.WB.Web/assets/images/awards/emergingmarkets2006.gif", title: "Flower4", caption: "Most Improved International Islamic Bank", website: "#", newwin : false},
    {url: "../SCB.WB/SCB.WB.Web/assets/images/awards/energyrisk2007.gif", title: "Flower5", caption: "Best Transaction Bank in Korea - SC First Bank", website: "#", newwin : false},
    {url: "../SCB.WB/SCB.WB.Web/assets/images/awards/euromoney2006.gif", title: "Banker of the year 2006", caption: "Best Transaction Bank in Korea - SC First Bank", website: "#", newwin : false},
    {url: "../SCB.WB/SCB.WB.Web/assets/images/awards/euromoney2007.gif", title: "Banker of the year 2006", caption: "Best Transaction Bank in Korea - SC First Bank", website: "#", newwin : false},
    {url: "../SCB.WB/SCB.WB.Web/assets/images/awards/financeasia2006.gif", title: "Banker of the year 2006", caption: "Best Transaction Bank in Korea - SC First Bank", website: "#", newwin : false},
    {url: "../SCB.WB/SCB.WB.Web/assets/images/awards/global2007.gif", title: "Banker of the year 2006", caption: "Best Transaction Bank in Korea - SC First Bank", website: "#", newwin : false},
    {url: "../SCB.WB/SCB.WB.Web/assets/images/awards/globalfinance.gif", title: "Banker of the year 2006", caption: "Best Transaction Bank in Korea - SC First Bank", website: "#", newwin : false},
    {url: "../SCB.WB/SCB.WB.Web/assets/images/awards/ifrasia2006.gif", title: "Banker of the year 2006", caption: "Best Transaction Bank in Korea - SC First Bank", website: "#", newwin : false},
    {url: "../SCB.WB/SCB.WB.Web/assets/images/awards/islamicfinance2006.gif", title: "Banker of the year 2006", caption: "Best Transaction Bank in Korea - SC First Bank", website: "#", newwin : false},
    {url: "../SCB.WB/SCB.WB.Web/assets/images/awards/isr2006.gif", title: "Banker of the year 2006", caption: "Best Transaction Bank in Korea - SC First Bank", website: "#", newwin : false},
    {url: "../SCB.WB/SCB.WB.Web/assets/images/awards/thebanker2006.gif", title: "Banker of the year 2006", caption: "Best Transaction Bank in Korea - SC First Bank", website: "#", newwin : false},
    {url: "../SCB.WB/SCB.WB.Web/assets/images/awards/tradefinance.gif", title: "Banker of the year 2006", caption: "Best Transaction Bank in Korea - SC First Bank", website: "#", newwin : false},
    {url: "../SCB.WB/SCB.WB.Web/assets/images/awards/euromoneycash2006.gif", title: "Banker of the year 2006", caption: "Best Transaction Bank in Korea - SC First Bank", website: "#", newwin : false}
];

function mycarousel_itemLoadCallback(carousel, state)
{
    for (var i = carousel.first; i <= carousel.last; i++) {
        if (carousel.has(i)) {
            continue;
        }

        if (i > mycarousel_itemList.length) {
            break;
        }

        carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[i-1]));
    }
};
  
function mycarousel_getItemHTML(item)
{
    var mainHTML = '<img src="' + item.url + '" alt="' + item.title + '" alt="' + item.title + '" /><p>';
    
    if(item.url=="") {
        mainHTML ='<p>';
    }
    
    if(item.website == "") {
    
        mainHTML += item.caption +'</p>';
      
    } else {
      
        if(item.newwin == true) {
        
            mainHTML += '<a class="newwin" title="' + item.caption + '" href="'+ item.website +'">'+ item.caption +'</a></p>';
            
        } else {
        
            mainHTML += '<a title="' + item.caption + '" href="'+ item.website +'">'+ item.caption +'</a></p>';
          
        }
          
    }
    
    return mainHTML;
};

function newwin_setlinks() 
{
    var links = $('a.newwin');
    $(links).click(function() 
    {
        
        var href = $(this).attr('href');
        window.open(href,'newWinW');
        return false;
    
    });
};