var cboxOpened = 0;
    
    $(document).bind('cbox_complete', function(){
        cboxOpened = 1;
        sifr_replace();
        
        var height = $(window).height()/2 - $('#colorbox').height()/2;
        $('#colorbox').css('top', height);
        $('#colorbox').css('position','fixed');
        
    });
    $(document).bind('cbox_closed', function(){
        cboxOpened = 0;
    });
    //$.fn.colorbox.init();
    //$.fn.colorbox.position();
    $(window).scroll(function () {
        // move colorbox when scrolling
        if (cboxOpened) $.fn.colorbox.position();
    });
    
    var clicked = false;
    
    $('#AddToBasketButton1').click(function() {
        if (!clicked) {
            clicked = true;
            $(this).fadeTo('slow',0.33);
            return true;
        } else {
            return false;
        }
    });
    
    function enableGetPriceButton(evt) {
        // enable and grey in getPrice button
        var evt = (evt) ? evt : (window.event) ? event : null ;
        var keyCode = evt.keyCode ? evt.keyCode :
               evt.charCode ? evt.charCode :
               evt.which ? evt.which : void 0;  

        if ( !(keyCode in oc([9,33,34,35,36,37,38,39,40,116])) ) {
            $('#getPriceButton').get(0).disabled = false;
            $('#getPriceButton').fadeTo('fast', 1.00);
        } 
    }
    
    function getDeliveryCharge(param1) {
        if ($('#postcode').length == 0) {
            // do not know why this function called
            return;
        }
        // get postcode
        var postcode = $('#postcode').val();
        var firstrun = (param1 != undefined) ? param1 : false;
        $('#postcodeError').html('');
        if (typeof console != 'undefined') {
            console.log(postcode);
        }
        if (postcode.length < 4) {
            // postcode not set or have less than 4 characters.
            $('#chargeValue').html('<span id="enterPostcode">Enter postcode</span>');
            if (! firstrun) {
                alert('Enter at least 4 digits of your postcode');
            }
            return;
        }
        
        // disable and grey out getPrice button if postcode was entered and have at least 4 characters
        $('#getPriceButton').get(0).disabled = true;
        $('#getPriceButton').fadeTo('fast', 0.5);
        
        // Set calculating messages
        $('#chargeValue').html("<span id='calcMessage'> Calculating...</span>");
        
        // send request to calculation procedure
        var params = { postcode: postcode };
        $.post('/service/getNDDCost', params, function(data) {
            if (data == 'n/a') {
                // postcode was not recognized
                $('#postcodeError').html("Your postcode has not been recognised, please contact the sales team on <tmpl_var site_owner_phone>");
                $('#chargeValue').html('n/a');
            } else {
                // postcode was recognized
                if (data == 'no_products') {
                    $('#chargeValue').html("No products in basket");
                } else {
                    shipcost = data;
                    $('#chargeValue').html(currency_symbol + shipcost);
                }
            }
        });
    }
    
    function getServerTime() {         
        var cur_date = new Date();
        var cur_sdate = new Date(sync_date.getTime() +  (cur_date.getTime()- start_date.getTime()));
        var pm13_date =  new Date(cur_sdate.getFullYear(),cur_sdate.getMonth(),cur_sdate.getDate(),13);

        if(pm13_date.getTime()>cur_sdate.getTime()){
            var o = $("#flashVars2");
            o.val("startYear="+cur_sdate.getFullYear()+"&startMonth="+cur_sdate.getMonth()+"&startDay="+cur_sdate.getDate()+"&startHour="+cur_sdate.getHours()+"&startMinute="+cur_sdate.getMinutes()+"&startSecond="+cur_sdate.getSeconds()+"");
            //alert(o.val());
            $("#before1pmMessage").css("display","block");
            $("#after1pmMessage").css("display","none");
        }
        else{
            $("#before1pmMessage").css("display","none");
            $("#after1pmMessage").css("display","block");            
        }
        return false;
    }

