var main_image_filepath = '';

function change_suit_image(filename)
{
  

    clearTimeout(restore_suit_image_timer);
    var main_photo = document.getElementById("zoom1").firstChild;

    main_image_filepath = main_photo.src;

    var new_src = suitsMenConstants['url_path']+'/suit-images/info-main/'+filename+'.jpg';
    var new_zoom_src = suitsMenConstants['url_path']+'/suit-images/full-size/'+filename+'.jpg';
    main_photo.setAttribute("src",new_src);

    MagicZoom_stopZooms();
    MagicThumb.stop();
    $('#zoom_instructions').css('display','none');
    $('#zoom_activation').css('display','inline');
    if($("#zoom1").hasClass("MagicZoom")) $("#zoom1").removeClass("MagicZoom");
    if($("#zoom1").hasClass("MagicThumb"))$("#zoom1").removeClass("MagicThumb");
    $("#zoom1").unbind('mouseover');
    $("#zoom1").unbind('mouseout');
    $("#zoom1").click(function(){activate_zoom();return false;});

    var zoomLink = document.getElementById('zoom1');
    // Change the URL for the large image
    zoomLink.href = new_zoom_src;
    // Re-initialize Magic Zoom - NO we now let the click to activate reinit
    //MagicZoom_findZooms();
    //MagicThumb.refresh();
  
}

function temporarily_change_suit_image(filename)
{
 	clearTimeout(restore_suit_image_timer);
	var main_photo = document.getElementById("zoom1").firstChild;
	var new_src = suitsMenConstants['url_path']+'/suit-images/info-main/'+filename+'.jpg';
	main_photo.setAttribute("src",new_src);
}

var restore_suit_image_timer = '';
function restore_suit_image(filename)
{
	var do_restore = "restore_suit_image_now()";
	restore_suit_image_timer = setTimeout(do_restore,300);
}

function restore_suit_image_now()
{
  var main_photo = document.getElementById("zoom1").firstChild;
  if(main_image_filepath != '')
  {
    main_photo.setAttribute("src",main_image_filepath);
  }else
  {
    main_photo.setAttribute("src",default_main_image_filepath);
  }
}


function change_main_image(filename)
{
  
  $('#colour_photo_coming_soon_selected').remove();
  
  if(filename == 'colour_photo_coming_soon')
  {
    var main_photo = document.getElementById("zoom1").firstChild;
    if(main_image_filepath != '')
    {
      main_photo.setAttribute("src",main_image_filepath);
    }else
    {
      main_photo.setAttribute("src",default_main_image_filepath);
    }
    var new_src = suitsMenConstants['url_path']+'/recoloured-images/info-main/'+filename+'.png';
    $(main_photo).parent().append("<img style='position:absolute; top:0; left:13px;' id='colour_photo_coming_soon_selected' src='"+new_src+"' />");
    
  }else
  {    
    var main_photo = document.getElementById("zoom1").firstChild;

    var new_src = suitsMenConstants['url_path']+'/recoloured-images/info-main/'+filename+'.jpg';
    main_photo.setAttribute("src",new_src);

    main_image_filepath = new_src;

    var zoom_src = suitsMenConstants['url_path']+'/recoloured-images/full-size/'+filename+'.jpg';

    MagicZoom_stopZooms();
    MagicThumb.stop();
    $('#zoom_instructions').css('display','none');
    $('#zoom_activation').css('display','inline');
    if($("#zoom1").hasClass("MagicZoom")) $("#zoom1").removeClass("MagicZoom");
    if($("#zoom1").hasClass("MagicThumb"))$("#zoom1").removeClass("MagicThumb");
    $("#zoom1").unbind('mouseover');
    $("#zoom1").unbind('mouseout');
    $("#zoom1").click(function(){activate_zoom();return false;});

    var zoomLink = document.getElementById('zoom1');
    if(zoomLink)
    {
      // Change the URL for the large image
      zoomLink.href = zoom_src;
    }
    // Re-initialize Magic Zoom - NO we now let the click to activate reinit
    //MagicZoom_findZooms();
    //MagicThumb.refresh();
  }
}



function temporarily_change_main_image(filename)
{
  clearTimeout(restore_image_timer);
  $('#colour_photo_coming_soon_selected').css({'display':'none'});
  $('#colour_photo_coming_soon').remove();
  if(filename == 'colour_photo_coming_soon')
  {   
    var main_photo = document.getElementById("zoom1").firstChild;
    if(main_image_filepath != '')
    {
      main_photo.setAttribute("src",main_image_filepath);
    }else
    {
      main_photo.setAttribute("src",default_main_image_filepath);
    }
    var new_src = suitsMenConstants['url_path']+'/recoloured-images/info-main/'+filename+'.png';
    $(main_photo).parent().append("<img style='position:absolute; top:0; left:13px;' id='colour_photo_coming_soon' src='"+new_src+"' />");
    
  }else
  { 
    var main_photo = document.getElementById("zoom1").firstChild;
    var new_src = suitsMenConstants['url_path']+'/recoloured-images/info-main/'+filename+'.jpg';
    main_photo.setAttribute("src",new_src);
  }
}

var restore_image_timer = '';
function restore_main_image(filename, recoloured)
{
  $('#colour_photo_coming_soon_selected').css({'display':'block'});
  $('#colour_photo_coming_soon').remove();    
  var do_restore = "restore_main_image_now('"+filename+"', '"+recoloured+"')";
  restore_image_timer = setTimeout(do_restore,300);
}


function restore_main_image_now(filename, recoloured)
{
  var main_photo = document.getElementById("zoom1").firstChild;
  if(main_image_filepath != '')
  {
    main_photo.setAttribute("src",main_image_filepath);
  }else
  {
    main_photo.setAttribute("src",default_main_image_filepath);
  }
}

function hide_size_chart()
{
	var size_chart = document.getElementById("size_chart");
	if(size_chart)
	{
		size_chart.style.display = 'none';
	}
}

function show_size_chart()
{
	var size_chart = document.getElementById("size_chart");
	if(size_chart)
	{
		size_chart.style.display = '';
	}
}



function message_on()
{
    var inactive_buy_message = document.getElementById('inactive_buy_message');
	if(inactive_buy_message)
	{
		inactive_buy_message.style.display = 'block';
	}
}

function message_off()
{
    var inactive_buy_message = document.getElementById('inactive_buy_message');
	if(inactive_buy_message)
	{
		inactive_buy_message.style.display = 'none';
	}
}

function toggle_panel(panel) {
	var selections_panel = document.getElementById('selections_panel');
	var description_panel = document.getElementById('description_panel');
	var size_chart_panel = document.getElementById('size_chart_panel');
	var feedback_panel = document.getElementById('feedback_panel');

	var selections_tab = document.getElementById('selections_tab');
	var description_tab = document.getElementById('details_tab');
	var size_chart_tab = document.getElementById('size_chart_tab');
	var feedback_tab = document.getElementById('feedback_tab');

	if(panel != 'selections')
	{
		selections_panel.style.display = 'none';
		selections_tab.className = 'normal';
	}else
	{
		selections_panel.style.display = 'block';
		selections_tab.className = 'active';
    _gaq.push(['_trackEvent', 'Product Info Panel', 'Tab Click', 'Selections']);
	}
	if(panel != 'details')
	{
		description_panel.style.display = 'none';
		description_tab.className = 'normal';
	}else
	{
		description_panel.style.display = 'block';
		description_tab.className = 'active';
    _gaq.push(['_trackEvent', 'Product Info Panel', 'Tab Click', 'Description']);
	}
	if(panel != 'size_chart')
	{
		size_chart_panel.style.display = 'none';
		if(size_chart_tab)
		{
			size_chart_tab.className = 'normal';
		}
	}else
	{
		size_chart_panel.style.display = 'block';
		if(size_chart_tab)
		{
			size_chart_tab.className = 'active';
      _gaq.push(['_trackEvent', 'Product Info Panel', 'Tab Click', 'Size Chart']);
		}
	}
	if(panel != 'feedback')
	{
		feedback_panel.style.display = 'none';
		feedback_tab.className = 'normal';
	}else
	{
		feedback_panel.style.display = 'block';
		feedback_tab.className = 'active';
    _gaq.push(['_trackEvent', 'Product Info Panel', 'Tab Click', 'Feedback']);
	}
	return false;
}

function  toggle_unfinished(display_state)
{
	var unfinished = document.getElementById("unfinished");
	if(display_state == 'show') unfinished.style.display = 'block'; else unfinished.style.display = 'none';
}


