﻿
//JavaScript framework for Borget Dancha
//
// Borget Solutions
$(function () {
    $(".PopupLink").click(function (e) {
        e.preventDefault();
        var $this = $(this);
        var targetpage = $(this).attr('href');
        var titlereq = '';
        targeturl = baseurl + targetpage;
        titlereq = $(this).attr('title')
        $('#Popupiframe').attr('src', targeturl);
        calldialog(titlereq, $this);
    });
}); 

//Common Function To Call Dialog
function calldialog(titlereq, $this) {
    //Height Check Logic start
    var f = document.getElementById('Popupiframe');
    var size;
    size = f.contentWindow.document.body.scrollHeight + 500;
    f.style.height = size + "px";
    //Height Check Logic end
    $('#iframeplaceholder').dialog({
      title: ($this.attr('title')) ? $this.attr('title') : titlereq,
      autoOpen: true,
      width: 834,
      modal: true,
      resizable: true,
      autoResize: true
     });
}

function scrolltarget(target) {

    var target_offset = $("#" + target).offset();
    var target_top = target_offset.top;

    //goto that anchor by setting the body scroll top to anchor top
    $('html, body').animate({ scrollTop: target_top }, 1300);
}

$(document).ready(function () {

    $(".scroll").click(function (event) {
        event.preventDefault();
        var full_url = this.href;
        //split the url by # and get the anchor target name - home in mysitecom/index.htm#home
        var parts = full_url.split("#");
        var target = parts[1];
        scrolltarget(target);
    });

    scrollspriteimage();

});


function scrollspriteimage() {
    for (var i = 0; i < 100; i++) {
        $(".scroll-image")
        .css({ backgroundPosition: '0 0' })
        .animate({ backgroundPosition: '(0 0)' }, 2000).delay(4000)
        .animate({ backgroundPosition: '(0 -75px)' }, 2000).delay(4000)
        .animate({ backgroundPosition: '(0 -150px)' }, 2000).delay(4000)
        .animate({ backgroundPosition: '(0 -225px)' }, 2000).delay(4000)
        .animate({ backgroundPosition: '(0 -265px)' }, 1000)
        .animate({ backgroundPosition: '(0 50px)' }, 1)
    }
  }
  // Selected plans logic
 // ===========================
  var str = "", planName = ""; //Plan Name
  var id = 0, flag = false;

  $("#list").hide();          //hide the div-list 

  function removePolicy(i) {

      if (i == 0) {
          $("input[ident='sel-in'][@type='checkbox'][checked='true']").attr('checked', false);
      }

      $("input[ident='sel-in'][@type='checkbox'][checked='true']").each(function () {

          if ($(this).val() == i)
              $(this).attr('checked', false);

      });

      displaySelected();
  }



  function displaySelected() {

      str = "", flag = false;

      $("input[ident='sel-in'][@type='checkbox'][checked='true']").each(function () {

          flag = true;
          id = $(this).val();
          planName = $("#" + id).text();
          str += '<span onclick="javascript:removePolicy(' + id + ');"><span class="search-selected" data="' + id + '">' + planName + '</span> x</span>' + '&nbsp;&nbsp;';
      });

      if (flag) {
          str += '<span onclick="javascript:removePolicy(0);"><span class="search-selected">Clear All</span></span>';

          $("#list p:last").html(str);
          $("#list").show();
      }
      else
          $("#list").hide();

  }


  $(function () {

      //To Work when the page is refreshed
      displaySelected();
      //Add an event handler to all the checkbox
      $("input[ident='sel-in']").click(function () {

          var count = $("input[ident='sel-in'][@type='checkbox'][checked='true']").length;
          if (count >= 5) {
              alert("Sorry you can only select 4 policies for comparision");
              $(this).removeAttr("checked");
          }
          else
              displaySelected();


      });

  });


  // Show or hide more button

  $(function () {
      var showText1 = "Show More";
      var showText2 = "Show Less";

      //Show,hide functionality

      $("#show-result-list").html(showText1);

      $("tr[page='hide']").hide();

      $("#show-result-list").click(function (event) {

          if ($(this).html() == showText1) {
              $(this).html(showText2);
              $("tr[page='hide']").show();
              //$('.hide').css('display', 'block');
          }
          else {
              $(this).html(showText1);
              $("tr[page='hide']").hide();
              //$('.hide').css('display', 'none');
          }

      });

  });

// BG image animation
(function ($) {
    $.extend($.fx.step, {
        backgroundPosition: function (fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem, 'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0], start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0], end[2]];
                fx.unit = [end[1], end[3]];
            }
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
            fx.elem.style.backgroundPosition = nowPosX[0] + ' ' + nowPosX[1];

            function toArray(strg) {
                strg = strg.replace(/left|top/g, '0px');
                strg = strg.replace(/right|bottom/g, '100%');
                strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g, "$1px$2");
                var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
                return [parseFloat(res[1], 10), res[2], parseFloat(res[3], 10), res[4]];
            }
        }
    });
})(jQuery);
