/*
* name: fsnm.ui.js
* author: IP
* notes: global ui functions
*/

//window onload function
$(document).ready(function() {

    setLinkRel();
    ftnSetVisualElements();
    ftnGetWidth();
    ftnSetTools();    
});

// open windows in external window
function setLinkRel()
{
  $('a[rel="external"]').click( function() {
      window.open( $(this).attr('href') );
      return false;
  });
}

function ftnSetVisualElements()
{
   /* corners 
   $(".corner").corner("bottom");
   $("body").attr("style","background:#333333;");
   $(".corner").corner("top");
   $("body").removeAttr("style");
   $(".corner div:first").removeAttr("style").attr("style","margin:-1em 0 0 0;");
   $(".corner div:first + div").removeAttr("style").attr("style","margin:-.8em 0 0 0;");
   
   $(".corner-bottom").corner("bottom");
   $(".corner-bottom div:first").remove();
   */
   
   /* ring binders */
   var ringBinderImg = new Image();
   ringBinderImg = $(ringBinderImg);
   ringBinderImg.attr("src", "/images/greenline/site/elements/ringbinder.png").attr("alt", "").addClass("ringbinder-left");
   
   /*$("#route-planner").next(".my-arriva").children("#my-arriva").append(ringBinderImg);
   
   ringBinderImg.clone(true).removeClass("ringbinder-left").addClass("ringbinder-right").appendTo("#my-arriva");
   $("#route-planner").next(".my-arriva").children("#my-arriva").css("margin-top", ".3em");
   
   $(".content-box").next(".content-box").append(ringBinderImg.clone(true));
   $(".content-box").next(".content-box").append(ringBinderImg.clone(true).removeClass("ringbinder-left").addClass("ringbinder-right"));
   
   $(".content-box").prev(".content-box").css("margin-bottom",".3em");*/
   
   
   
   /* pin & paper curl */
   var pinImg = new Image();
   pinImg = $(pinImg);
   pinImg.attr("src", "/images/greenline/site/elements/pin.png").attr("alt", "").addClass("su-pin");
   
   $("#service-updates").append(pinImg);
   
   var curlImg = new Image();
   curlImg = $(curlImg);
   curlImg.attr("src", "/images/greenline/site/elements/page-curl.png").attr("alt", "").addClass("su-curl");
   
   $("#service-updates").append(curlImg);
   
   $("#contact-info").append(curlImg.clone(true))
   $("#ask-question").append(curlImg.clone(true))
   
   /* rounded corners for user option buttons 
   var cornerImg = new Image();
   $(cornerImg).attr("src", "/images/greenline/site/elements/corner-bl.gif").attr("alt", "").addClass("corner-bl");
   $(".user-options li").append(cornerImg);
   
   var cornerImg = new Image();
   $(cornerImg).attr("src", "/images/greenline/site/elements/corner-br.gif").attr("alt", "").addClass("corner-br");
   $(".user-options li").append(cornerImg);
   
   var cornerImg = new Image();
   $(cornerImg).attr("src", "/images/greenline/site/elements/corner-tl.gif").attr("alt", "").addClass("corner-tl");
   $(".user-options li").append(cornerImg);
   
   var cornerImg = new Image();
   $(cornerImg).attr("src", "/images/greenline/site/elements/corner-tr.gif").attr("alt", "").addClass("corner-tr");
   $(".user-options li").append(cornerImg);
   */
  
   
}

function ftnGetWidth()
{
   var _windowWidth
   var _wrapperWidth
   var _convertWidth
   
   _windowWidth = $(window).width();
   _wrapperWidth = $("#header-wrapper").width();
   //alert("windowWidth: "+_windowWidth+" wrapperWidth: "+_wrapperWidth);
   
   if(_windowWidth<_wrapperWidth) //converts to ems
   {
      _convertWidth = _wrapperWidth/12;
      //alert("change site : "+_convertWidth);
      $("#header-container").attr("style","width:"+_convertWidth+"em;");
      $("#primary-navigation-container").attr("style","width:"+_convertWidth+"em;");
      $("#content-container").attr("style","width:"+_convertWidth+"em;");
      $("#footer-container").attr("style","width:"+_convertWidth+"em;");
   } else {
      $("#header-container").attr("style","width:100%;");
      $("#primary-navigation-container").attr("style","width:100%;");
      $("#content-container").attr("style","width:100%;");
      $("#footer-container").attr("style","width:100%;");
   } 
}

function ftnSetTools()
{
    // $("#pagetools").load("/includes/greenline/basemarkup/pagetools.htm", ftnTextsize) // Existing one
    $("#pagetools").load("/Controls/pagetools.htm", ftnTextsize)   
}

function ftnTextsize()
{
  // Reset Font Size
  var originalFontSize = $("body").css("font-size");
  //alert(originalFontSize)
  $("#resetTxt").click(function(){
    $("body").css("font-size", originalFontSize);
    ftnGetWidth()
  });
  
  // Increase Font Size
  $("#increaseTxt").click(function(){
    var currentFontSize = $("body").css("font-size");
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum*1.2;
    //alert(newFontSize)
    $("body").css("font-size", newFontSize);
    ftnGetWidth()
    return false;
  });
  
  // Decrease Font Size
  $("#decreaseTxt").click(function(){
    var currentFontSize = $("body").css("font-size");
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum/1.2;
    //alert(newFontSize)
    $("body").css("font-size", newFontSize);
    ftnGetWidth()
    return false;
});

$("#bookmarkPage a").click(function() {
    var bookmarkUrl = window.location.href;
    var bookmarkTitle = document.title;

    if (document.all) // IE
    {
        window.external.AddFavorite(bookmarkUrl, bookmarkTitle);
    }
    else if (window.sidebar)  // Firefox
    {
        window.sidebar.addPanel(bookmarkTitle, bookmarkUrl, "");
    }
    return false;
});


$("#printThisPage a").click(function() {
    window.print();
    return false;
});
 
}

function ftnHideShow()
{
  var openImg = new Image();
  openImg = $(openImg);
  openImg.attr("src", "/images/greenline/site/icons/open.png").attr("alt", "open panel").addClass("open");
  $("h2.click-area").prepend(openImg);
    
  $(".hide-area").hide();
  
  $("h2.click-area").click(function() { 
      $(this).nextAll(".hide-area:first").animate({height: "hide", opacity: "hide"}, 10);
      $(this).children("img").attr("src", "/images/greenline/site/icons/open.png").attr("alt", "open panel")

      if($(this).nextAll(".hide-area:first").is(":hidden"))
      {
        $(this).nextAll(".hide-area:first").animate({height: "show", opacity: "show"}, 10);
        $(this).children("img").attr("src", "/images/greenline/site/icons/close.png").attr("alt", "close panel")

		  }
  });
}

function ftnPopUp() {
    $("a[href=#register-confirmation]").click(function() {
        $('#map_player').css('visibility', 'hidden');
        $.modal($("#register-confirmation"), { onShow: ftnModalShow });
    });
}

function ftnModalShow() {
    bindForm("form0")
}

//function customValidationStyle(oElem, isValid) {
//    if ("INPUT" == oElem.tagName || "TEXTAREA" == oElem.tagName) {
//        if (isValid) {
//            oElem.style.backgroundColor = "";
//            oElem.style.border = "";
//            $(oElem).removeClass("error");
//            $(oElem).next("label.error").remove();
//        }
//        else {
//            oElem.style.backgroundColor = "#ffeeee";
//            oElem.style.border = "1px solid #cc0000";
//            $(oElem).addClass("error");
//            $(oElem).next("label.error").remove();
//            $(oElem).parent().append("<label class='error'>#The above field is required</label>");
//        }
//    }
//    else {
//        design_validationStyle(oElem, isValid);
//    }
//}

//function EkFmValidate(formObj) {
//    var strError = ''; var e = null;
//    if (strError == '' && 'function' == typeof design_validateHtmlForm) {
//        e = design_validateHtmlForm(formObj);
//        if (e) { strError = e.title; }
//    }
//    if (strError == '') { return true; }
//    else {
//        $("div.error").html("The form has errors, highlighted below with a hash symbol (#)").show()
//        if ('function' == typeof e.scrollIntoView || 'object' == typeof e.scrollIntoView) e.scrollIntoView();
//        if ('function' == typeof design_canElementReceiveFocus) {
//            if (design_canElementReceiveFocus(e)) e.focus();
//        } else { e.focus(); }
//        return false;
//    }
//}

  

