/*** Common Helpers ***/

function createCookie(name, value, days)
{
  if (days)
  {
    var date = new Date();
    date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
    var expires = "; expires=" + date.toGMTString();
  }
  else
  {
    var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
  }
}

/*** Search Citywire ***/
function SearchCitywire()
{
  window.location = "search.aspx?phrase=" + $('div#searchBar input#keywords').val();
}

/*** Open legal text in a popup ***/
function LegalWindow(path, name)
{
  window.open(path, name, 'width=500,height=600,scrollbars=yes,resizable=yes,toolbar=no,directories=no,location=no,menubar=no,status=no,left=50,top=0');
  return false;
}



/*** END Common Helpers***/




/*** Stuff that happens after the page has loaded ***/
$(function() {
      
    // Move header before img to achieve better layout and adjust floating and padding values
    $('div.column-1 div.box img.headlineImage + h2').each(function() {
        var h2 = $(this);
        var img = h2.prev();

        img.insertAfter(h2);
    });


    // Search box watermarking
    $('.cwsearchWatermark').focus(function() {
        $(this).removeClass('cwsearchWatermark');
    }).blur(function() {
        if ($(this).val() == '') {
            $(this).addClass('cwsearchWatermark');
        }
    });


    // FTSE Chart switching
    $('#ddlftsemrktdata').change(function() {
        var ftseid = $(this).val();

        $('.ftsemrktdata:visible').fadeOut("normal", function() {
            $('#' + ftseid).fadeIn("normal");
        });
    });


    // Promotion box slider (relies on jQuery CodaSlider plugin)
    $(".promotionBox-slider").codaSlider();

    // Promotion box cycling (relies on jQuery Cycle Plugin)
    $(".promotionBox").cycle({
        pause: 1,       // pause on hover
        timeout: 5000   // 5 seconds per item
    });

    // scrollable boxes (relies on jquery tools)
    $("div.scrollable").scrollable({
        size: 3
    }); 
});



/*** For website v2 ***/
function WriteScreenRes() {
  createCookie("sr", screen.width + '|' + screen.height, 365);
}

WriteScreenRes();
//*** For website v2 ***/

