var popup_delay = 500;
var popup_show_speed = 10;
var popup_hide_speed = 750;
var b_hide_product_popup = false;
var show_product_popup_timeout;
var hide_product_popup_timeout;
$(function(){
initialise_product_popups();
});
function initialise_product_popups(){
$('.list-subheader').append('<div class="loading-animation">Loading...</div>');
var product_images = $('li.product-tile img.product');
product_images.mouseover(function(){
b_hide_product_popup = false;
var product_id = $(this).parents('li.product-tile').attr('id').replace('product-tile-', '');
show_product_popup_init(product_id);
});
var product_links = $('li.product-tile h5 a');
product_links.mouseover(function(){
b_hide_product_popup = false;
var product_id = $(this).parents('li.product-tile').attr('id').replace('product-tile-', '');
show_product_popup_init(product_id);
});
product_images.mouseout(function(){
b_hide_product_popup = true;
hide_product_popup_timeout = setTimeout(hide_product_popup, 50);
});
product_links.mouseout(function(){
b_hide_product_popup = true;
hide_product_popup_timeout = setTimeout(hide_product_popup, 50);
});
}
var current_product_id;
function show_product_popup_init(product_id){
if(product_id == null || product_id == current_product_id || show_product_popup_timeout != null){
return false;
}
clearTimeout(hide_product_popup_timeout);
show_product_popup_timeout = setTimeout(show_product_popup, popup_delay);
current_product_id = product_id;
}
function show_product_popup(){
if(hide_product_popup_timeout != null){
clearTimeout(hide_product_popup_timeout);
}
show_product_popup_timeout = null;
product_id = current_product_id;
if(b_hide_product_popup){
return false;
}
$('#phone-details-popup-wrapper').remove();
$('#pagewidth').after('<div id="phone-details-popup-wrapper"></div>');
var popup_content_vars = {};
popup_content_vars[product_id_var] = product_id;
show_loading_animation();
$('#phone-details-popup-wrapper').load(popup_content_url, popup_content_vars, product_popup_loaded);
current_product_id = product_id;
}
function product_popup_loaded(){
hide_loading_animation();
if(current_product_id == null){
$('#phone-details-popup-wrapper').hide();
return false;
}
//console.debug(current_product_id)
var product_tile = $('#product-tile-' + current_product_id);
var details_popup = $('#phone-details-popup-wrapper .product-popup');
details_popup.css({top: product_tile.offset().top + 5, left: product_tile.offset().left + 36}).fadeIn(popup_show_speed);
details_popup.mouseover(function(){
//console.debug('details_popup.mouseover')
b_hide_product_popup = false;
});
details_popup.mouseout(function(e){
//console.debug('details_popup.mouseout')
b_hide_product_popup = true;
setTimeout(hide_product_popup, 10);
});
$('#phone-details-popup-close').click(function(){
current_product_id = null;
b_hide_product_popup = true;
hide_product_popup();
});
$('#product-configuration-colour').change(function(x){
var colour = $(this).find('option:selected').attr('value');
$('.product-popup img.product').attr('src', coloured_product_image_url_template.replace('{product_id}', current_product_id).replace('{colour}', colour));
});
initialise_contract_length_select();
}
function hide_product_popup(){
//console.debug('hide_product_popup()')
if(b_hide_product_popup){
current_product_id = null;
$('#phone-details-popup-wrapper .product-popup').fadeOut(popup_hide_speed);
}
}
function show_loading_animation(){
$('.loading-animation').fadeIn('def');
}
function hide_loading_animation(){
$('.loading-animation').fadeOut('slow');
}

