
$(document).ready(function(){

  $("div.menu > ul > li, .infoKiosk, #catalogItem, div.topicsList").each(function(){
    $(this).prepend("<div class='lt'><div class='rt'></div></div>");
    $(this).append("<div class='lb'><div class='rb'></div></div>");
  })

  $(".infoKioskHalf").each(function(){
    $(this).append("<div class='lb'><div class='rb'></div></div>");
  })

  $(".featuredVideo").each(function(){
    $(this).prepend("<div class='rt'></div>");
  })

  $("div.menu > ul > li:has(ul)").addClass("biggerSpace");

  $("#tabs > ul > li").each(function(i){
    var innerCode = $(this).html();
    $(this).text("");
    $(this).prepend("<div class='l'><div class='r'>"+innerCode+"</div></div>");
    $(this).children("div.l").addClass("tab"+i);
  });

  $("#tabs").tabs();

  $("#catalogSearch > form").addClass("niceform");

  /////////////////////////////////////////
  // Featured Images kiosk
  /////////////////////////////////////////
  //
  // onclick for <a>
  //
  var ic_params = {contentCurrent:"Image {current} of {total}", contentPrevious:"prev"}
  $("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(ic_params,function(){showDownload()});
      $("div.lightBoxes #sel_item .newsImage a[rel=featuredImagesTitle]").colorbox(ic_params,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(ic_params,function(){showDownload()});
  $("a[rel=featuredImagesTitle]").colorbox(ic_params,function(){showDownload()});
  $("a[rel=featuredImagesMain]").colorbox(ic_params,function(){showDownload()});


  /////////////////////////////////////////
  // Featured Video kiosk
  /////////////////////////////////////////
  //
  // onclick for <a>
  //
  var vc_params = {contentCurrent:"Video {current} of {total}", contentPrevious:"prev"}
  $("ul#recent_videos a").click(function(){
      $("#sel_item_video").children("*").remove();
      $("div.lightBoxes ul#recent_videos .newsImage a").attr("rel","featuredVideos");
      $("#sel_item_video").prepend($(this).parents("li").children("div.newsBody").clone());
      $("ul#recent_videos 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_video .newsImage a[rel=featuredVideos]").colorbox(vc_params,function(){showDownload()});
      $("div.lightBoxes #sel_item_video .newsImage a[rel=featuredVideosTitle]").colorbox(vc_params,function(){showDownload()});

      return false;
    });

  //
  // First item is autoselected
  //
  $("div.lightBoxes ul#recent_videos .newsImage a.thmb_containter").attr("rel","featuredVideos");
  $("#sel_item_video").prepend($("ul#recent_videos a.thmb_containter:first").parents("li").children("div.newsBody").clone());
  $("ul#recent_videos .newsImageSmall:first img").addClass("thmb_sel");
  $("ul#recent_videos .newsImageSmall:first").siblings(".newsImage").children("a").removeAttr("rel");

  if($("ul#recent_videos li").size() == 1) $("ul#recent_videos").hide();

  /////////////////////////////////////////
  // Light Box
  /////////////////////////////////////////
  $("a[rel=featuredVideos]").colorbox(vc_params,function(){showDownload()});
  $("a[rel=featuredVideosTitle]").colorbox(vc_params,function(){showDownload()});


  $("body#indexPage div.newsCategory").each(function(){$(this).children("a:first").remove();}); $("div.newsCategory").prepend("Category");

//  $("div.center object").append("<param name='wmode' value='opaque' />");

});


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;
}
