var dialog_titles = {
  'all-vehicles': "/cars/all.xml",
  'all-vehicles-minimal': "/cars/all/minimal.xml",
  'compare-vehicles': "/cars/model/impreza/justy.xml",
  'single-vehicle-data': "/cars/model/impreza.xml",
  'vehicle-brand-subaru': "/cars/brand/subaru.xml",
  'all-news':"/news/all.xml",
  'news-pagination':"/news/per_page/15/page/2.xml",
  'news-limits':"/news/limit/10.xml",
  'news-minimal':"/news/all/minimal.xml",
  'content-detail':"/news/details/15.xml",
  'multiple-content':"/news/details/15/8.xml",
  'less':"/news/less/15.xml",
  'more':"/news/more/8.xml"
};
jQuery(document).ready(function(){
  form_dialog();
  live_examples();
});



function form_dialog(){
  if(jQuery('#auth_form').length){
    jQuery('#auth_form').dialog({autoOpen:false, title:"Request API Authentication Token", modal:true, width:500, height:300});
    jQuery('h3#request').hide();
    jQuery('.dialog').click(function(){
      jQuery('#auth_form').dialog('open');
      return false;
    });
  }
}

function live_examples(){
  if(! jQuery('#example_dialog').length){				
		jQuery('body').append('<div id="example_dialog"><iframe src="" frameborder="0" width="700" height="320" /></div>');
		jQuery('#example_dialog').dialog({autoOpen:false, width:750, height:400, modal:true});
	}
	
  jQuery('.live_example').click(function(){
    var ind = jQuery(this).find('a.hidden').attr('rel'), target_url = "http://api.imwww.co.uk/example-results/"+ind+'.xml';
    jQuery('#example_dialog iframe').attr('src', '').attr('src', target_url).load(function(){
  		jQuery('#example_dialog').dialog('open');
  		var dtitle = "Requested: http://03734ad.imwww.co.uk"+dialog_titles[ind];
  		jQuery('#example_dialog').dialog('option', 'title', dtitle);
  		jQuery('.ui-widget-overlay').fadeTo('fast','0.6');
  	});
    
  });
}