var customerReviewSection = null; 
var trackListingSection = null;
var basketURL = "";
addDOMLoadEvent(init);
function init() 
{
    UpdateLinks();
    if ( $('customerReviewDiv') != null )
    {
        customerReviewSection = new fx.Height('customerReviewDiv', {duration: 500});
        $('customerReviewSwitch').href = "javascript:toggleCustomerReviews();";
	}
    if ( $('trackListingDiv') != null )
    {
        trackListingSection = new fx.Height('trackListingDiv', {duration: 500});
        $('trackListingSwitch').href = "javascript:toggleTrackListing();";
	}
}
function toggleCustomerReviews()
{
    if ( customerReviewSection != null )
    {
        ChangeState('customerReviewHeaderDiv', 'customerReviewDiv', 'customerReviewButton', 'reviews');	
        customerReviewSection.toggle();
    }
}
function toggleTrackListing()
{
    if ( trackListingSection != null )
    {
        ChangeState('trackListingHeaderDiv', 'trackListingDiv', 'trackListingButton', 'tracks');	
        trackListingSection.toggle();
    }
}
function ChangeState(thelink, theslave, theimage, imageSuffix) 
{
    if($(theslave).style.height == '0px')
    {
        $(thelink).innerHTML = $(thelink).innerHTML.replace(/Show/g, 'Hide');
        $(theimage).src = "/img/btn-hide-" + imageSuffix + ".gif";
    }
    else
    {
        $(thelink).innerHTML = $(thelink).innerHTML.replace(/Hide/g, 'Show');
        $(theimage).src = "/img/btn-show-" + imageSuffix + ".gif";
    }       
}
function GetItemTitle()
{ 
    var title = '';
    if ( $('spanItemTitle') )
    { 
        if ( document.all )
            title = $('spanItemTitle').innerText;
        else
            title = $('spanItemTitle').textContent;
    }
    return title.replace(/[\n\r]/g, '');    
}
function StoreSearch()
{
    gPopupMaskId = "popupMaskStoreSearch";
    gPopupContainerId = "popupContainerStoreSearch";
    gPopFrameId = "popupFrameStoreSearch";
    gPopupInnerId = "popupInnerStoreSearch";
    if ( initPopUp() )
        showPopWin(460, 460);
}
function TellAFriend()
{
    gPopupMaskId = "popupMask";
    gPopupContainerId = "popupContainer";
    gPopFrameId = "popupFrame";
    gPopupInnerId = "popupInner";
    if ( initPopUp() )
        showPopWin(530, 530);
}
function AddToBasket()
{
  var w = window.open(buyURL, 'BRGBasket'); 
  if (w && !w.closed) 
  { 
    w.focus(); 
  } 
}
function ShowImageCollection(ASIN)
{
    var thumbnailWidth = parseInt(smallImageTotalWidth) + ( smallImageSet.length * 10 ) + 16;
    var largeWidth = parseInt(largeImageMaxWidth) + 16;
    var windowWidth = ( thumbnailWidth > parseInt(largeWidth) ) ? thumbnailWidth : largeWidth;
    if ( windowWidth > screen.width - 50 ) 
        windowWidth = screen.width - 50;
    var windowHeight = parseInt(largeImageMaxHeight) + parseInt(smallImageMaxHeight) + 136;

    ShowImageWindow('/Gift-Image-Collection.aspx', windowWidth, windowHeight, ASIN);
}
function ShowLargeImage(ASIN)
{
    var windowWidth = parseInt(largeImageWidth) + 16;
    var windowHeight = parseInt(largeImageHeight) + 104;
    ShowImageWindow('/Gift-Image.aspx', windowWidth, windowHeight, ASIN);
}
function ShowImageWindow(ImagePageURL, windowWidth, windowHeight, ASIN)
{
    if ( windowWidth < 260 )
        windowWidth = 260;

    var winLeft = ((screen.width-windowWidth)/2);
    var winTop = ((screen.height-windowHeight)/2);
    if (winTop < 0) winTop = 0;
    if (winLeft < 0) winLeft = 0;
	
    var windowStyle = 'width='+windowWidth+',height='+windowHeight+',top='+ winTop +',left='+ winLeft +',location=no,scrollbars=no,menubars=no,toolbars=no,resizable=yes,status=no';
    var w = window.open(ImagePageURL, ASIN, windowStyle);
    if (w && !w.closed) 
    { 
        w.focus(); 
    } 
}
