$(document).ready(function() {

  /////////////////////////////////////////
  // Featured Images kiosk
  /////////////////////////////////////////
  //
  // onclick for <a>
  //
  $("ul#recent_images a").click(function(){
      $("#sel_item").children("*").remove();
      $("div.lightBoxes ul#recent_images .newsImage a").attr("rel","featuredImages");
      $("#sel_item").prepend($(this).parents("li").children("div.newsBody").clone());
      $("ul#recent_images a.thmb_containter img").removeClass("thmb_sel");
      $(this).children("img").addClass("thmb_sel");
      $(this).parents(".newsImageSmall").siblings(".newsImage").children("a").removeAttr("rel");

//       $("div.lightBoxes #sel_item .newsImage a[rel=featuredImages]").colorbox({},function(){showDownload()});
//       $("div.lightBoxes #sel_item .newsImage a[rel=featuredImagesTitle]").colorbox({},function(){showDownload()});

      return false;
    });

  //
  // First item is autoselected
  //
  $("div.lightBoxes ul#recent_images .newsImage a.thmb_containter").attr("rel","featuredImages");
  $("#sel_item").prepend($("ul#recent_images a.thmb_containter:first").parents("li").children("div.newsBody").clone());
  $("ul#recent_images .newsImageSmall:first img").addClass("thmb_sel");
  $("ul#recent_images .newsImageSmall:first").siblings(".newsImage").children("a").removeAttr("rel");

  if($("ul#recent_images li").size() == 1) $("ul#recent_images").hide();

  /////////////////////////////////////////
  // Light Box
  /////////////////////////////////////////
//   $("a[rel=featuredImages]").colorbox({},function(){showDownload()});
//   $("a[rel=featuredImagesTitle]").colorbox({},function(){showDownload()});


  $("body#indexPage div.newsCategory").each(function(){$(this).children("a:first").remove();}); $("div.newsCategory").prepend("Category");

});


function prGetParamFromString(sString, sParam) 
{
 var sQS=sString.substring(sString.indexOf("?")+1);
 var sResult='';
 var aParams= sQS.split('&');
 for (var i=0; i<aParams.length; i++) {
	var n = aParams[i].indexOf('=');
	if (n > 0) {
		if(aParams[i].substring(0,n)==sParam){
			sResult = aParams[i].substring(n+1);
			break;
		}
	 }
 }
 return sResult;
}


function showDownload()
{
  $("#prDownload").attr("onsubmit","");

  $("#prDownload").submit(function(){
    $("#modalLoadedContent").load("srp-download.aspx?id="+prGetParamFromString($(this).attr("action"),"id")+" .servicesContentDiv");
    return false;
  });

  return false;
}
