﻿
 
 function CreateNewColorbox(targetURL, _width, _height)
 {     
       $.fn.colorbox({width:_width, height:_height,iframe:true, href: targetURL});  
 }

/*
   Initialize currency conversion elements.
*/
function InitializeCurrencyConversion()
{
 
     getAll_gp_currencySymbols();
     $('#currencies').hide();
     $('#convertedPrice').show();
     ConvertToEuros($('#price').text());
     $('#price').hide();
     
     $('#hrefConvertCurrency').click(function(){
      
        $('#currencies').toggle();
        //$('#convertedPrice').toggle();
     });

     $('select#convertTo').change(function() {

         var gp_from = 'USD';
         var gp_to = $('#convertTo').val()
         var gp_amount = $('#price').text();
         gp_amount = $.trim(gp_amount);
         $.getJSON("http://www.geoplugin.net/currency_converter.gp?jsoncallback=?",
            { from: gp_from, to: gp_to, amount: gp_amount },
             function(output) {

                 var outputcode = "&nbsp;" + output.to.code;
                 var outputsymbol = output.to.symbol + "&nbsp;&nbsp;";

                 $("#convertedPrice").html("" + outputsymbol + output.to.amount + outputcode + "");
                 $('#convertedPrice').show();
                 $('#currencies').hide();
             });
     });
} 
   
/**
*
*  Populate the drop down list of currencies and symbols.
*
**/
function getAll_gp_currencySymbols() { 
    $.getJSON("http://www.geoplugin.net/currency_symbols.gp?format=json&jsoncallback=?", 
        function(data){ 
            // var currencyCode = geoplugin_currencyCode(); 
            var toCurr = '';
            $.each(data, function(i,item){
               
                 // If the currency is not USD, add it to the list of possible conversions currencies.
                 if (i != 'USD')
                 {
                      toCurr += '<option value="'+ i +'">' + item.name + ' ' + (item.symbol?item.symbol:'') + '</option>';
                  
                 }
            }); 
            $("select#convertTo").html(toCurr); 
        }); 
}; 
 
 
/**
*
*  Used to do an initial conversion to euros on the property detail page.
*
**/ 
function ConvertToEuros(USDAmount)
{
    var gp_from = 'USD'; 
    var gp_to = 'EUR';
    var gp_amount = USDAmount; 
    gp_amount = $.trim(gp_amount);

    $.getJSON("http://www.geoplugin.net/currency_converter.gp?jsoncallback=?",
        { from: gp_from, to: gp_to, amount: gp_amount },
         function(output) {

             var outputcode = "&nbsp;" + output.to.code;
             var outputsymbol = output.to.symbol + "&nbsp;&nbsp;";
             $("#convertedPrice").html("" + outputsymbol + output.to.amount + outputcode + "");

         }); 
}
