/**
 *------------------------------------------------------------------------------------------+
 * COMPANY: Raven Developers 2011
 +------------------------------------------------------------------------------------------+
 * FILE INFO: Site wide Java Script functions
 +------------------------------------------------------------------------------------------+
 * WEBSITE: http://www.ravendevelopers.com
 +------------------------------------------------------------------------------------------+
 * Portions created by Anirudh K. Mahant are Copyright of Raven Developers (C) 2009.
 +------------------------------------------------------------------------------------------+
 * COPYRIGHT NOTICE:
 * The original author(s) retain all the copyrights of this file.
 * Portions created by Anirudh K. Mahant (original developer) are Copyright of Raven Developers (C) 2009.
 * Portions may contain jQuery JavaScript framework developed by John Resig and other
 * community members. More info at http://docs.jquery.com/About
 * jQuery LICENSE:
 * Copyright (c) 2008 John Resig (jquery.com)
 * Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses.
 +-------------------------------------------------------------------------------------------+
 */

function URLDecode(psEncodeString) {
  var lsRegExp = /\+/g;
  return unescape(String(psEncodeString).replace(lsRegExp, " "))
}

function ZebraTables() {
  theTable = jQuery.find("table.zebra-table");
  jQuery(theTable).each(function (i) {
    if (this) {
      jQuery(this).find("tr").each(function (i) {
        var zclass = (i % 2 == 0) ? "odd" : "even";
        jQuery(this).addClass(zclass)
      })
    }
  })
}

function ZebraUL() {
  theUL = jQuery(document).find("ul.zebra-ul");
  jQuery(theUL).each(function (i) {
    if (this) {
      jQuery(this).find("li").each(function (i) {
        var zclass = (i % 2 == 0) ? "odd" : "even";
        jQuery(this).addClass(zclass)
      })
    }
  })
}

function BlurFocusText() {
  theText = jQuery("input.blur-focus");
  jQuery(theText).each(function (i) {
    if (this) {
      jQuery(this).blur(function () {
        if (this.value == "") {
          this.value = this.defaultValue
        }
      });
      jQuery(this).focus(function () {
        if (this.value == this.defaultValue) {
          this.value = ""
        }
      })
    }
  })
}(function ($) {
  $.fn.superSelectify = function (options) {
    var defaults = {
      emptyClass: "empty",
      firstClass: "first",
      lastClass: "last",
      oddClass: "odd",
      evenClass: "even",
      nextClass: "next",
      siblingClass: "sibling",
      firstChildClass: "first-child",
      lastChildClass: "last-child",
      onlyChildClass: "only-child",
      directChildClass: "child",
      textInputClass: "text",
      passwordInputClass: "password",
      radioInputClass: "radio",
      checkboxInputClass: "checkbox",
      submitInputClass: "submit",
      imageInputClass: "image",
      resetInputClass: "reset",
      buttonInputClass: "button",
      fileInputClass: "file",
      hoverClass: "hover",
      manualSelectors: false,
      forceStylesheetParsing: false,
      additionalElementHash: {}
    };
    var options = $.extend(defaults, options);
    for (var className in options.additionalElementHash) {
      $(options.additionalElementHash[className]).addClass(className)
    }

    function getMatches(CSS) {
      function _match_item(reg, className) {
        try {
          var itemMatch = CSS.replace(/[\n\r]/gi, "").match(reg);
          if (itemMatch) {
            itemMatch = itemMatch.join(", ")
          }
          if (itemMatch) {
            $(itemMatch).addClass(className)
          }
        } catch (err) {}
      }

      function _match_hover(reg, className) {
        try {
          var itemMatch = CSS.replace(/[\n\r]/gi, "").match(reg);
          if (itemMatch) {
            itemMatch = itemMatch.join(", ")
          }
          if (itemMatch) {
            $(itemMatch).hover(function () {
              $(this).addClass(className)
            }, function () {
              $(this).removeClass(className)
            })
          }
        } catch (err) {}
      }
      _match_item(/[a-zA-Z0-9._+~#:\s-]*:empty/gi, options.emptyClass);
      _match_item(/[a-zA-Z0-9._+~#:\s-]*:first[^-]/gi, options.firstClass);
      _match_item(/[a-zA-Z0-9._+~#:\s-]*:last[^-]/gi, options.lastClass);
      _match_item(/[a-zA-Z0-9._+~#:\s-]*:nth-child\(odd\)/gi, options.oddClass);
      _match_item(/[a-zA-Z0-9._+~#:\s-]*:nth-child\(even\)/gi, options.evenClass);
      _match_item(/[a-zA-Z0-9._+~#:\s-]*?\+\s?[a-zA-Z0-9._+~#:-]*/gi, options.nextClass);
      _match_item(/[a-zA-Z0-9._+~#:\s-]*?\~\s?[a-zA-Z0-9._+~#:-]*/gi, options.siblingClass);
      _match_item(/[a-zA-Z0-9._+~#:\s-]*:first-child/gi, options.firstChildClass);
      _match_item(/[a-zA-Z0-9._+~#:\s-]*:last-child/gi, options.lastChildClass);
      _match_item(/[a-zA-Z0-9._+~#:\s-]*:only-child/gi, options.onlyChildClass);
      _match_item(/[a-zA-Z0-9._+~#:\s-]*\>\s?[a-zA-Z0-9._+~#:-]*/gi, options.directChildClass);
      _match_item(/[a-zA-Z0-9._+~#:\s-]*input\[type="text"\]/gi, options.textInputClass);
      _match_item(/[a-zA-Z0-9._+~#:\s-]*input\[type="password"\]/gi, options.passwordInputClass);
      _match_item(/[a-zA-Z0-9._+~#:\s-]*input\[type="radio"\]/gi, options.radioInputClass);
      _match_item(/[a-zA-Z0-9._+~#:\s-]*input\[type="checkbox"\]/gi, options.checkboxInputClass);
      _match_item(/[a-zA-Z0-9._+~#:\s-]*input\[type="submit"\]/gi, options.submitInputClass);
      _match_item(/[a-zA-Z0-9._+~#:\s-]*input\[type="image"\]/gi, options.imageInputClass);
      _match_item(/[a-zA-Z0-9._+~#:\s-]*input\[type="reset"\]/gi, options.resetInputClass);
      _match_item(/[a-zA-Z0-9._+~#:\s-]*input\[type="button"\]/gi, options.buttonInputClass);
      _match_item(/[a-zA-Z0-9._+~#:\s-]*input\[type="file"\]/gi, options.fileInputClass);
      _match_hover(/[a-zA-Z0-9._+~#:\s-]*:hover/gi, options.hoverClass);
      var importedCSS = CSS.match(/[a-zA-Z0-9\.\-_\+\s]*import([a-zA-Z0-9\.\-_\+\/]*\.css)/gi);
      if (importedCSS) {
        var fakeStyleSheet = [];
        for (stylesheet = 0; stylesheet < importedCSS.length; stylesheet++) {
          fakeStyleSheet["href"] = importedCSS[stylesheet];
          getCSS(fakeStyleSheet)
        }
      }
    }

    function ruleIterator(sheet) {
      var css = sheet.cssRules;
      for (var rule = 0; rule < css.length; rule++) {
        if (css[rule].styleSheet) {
          getCSS(css[rule].styleSheet)
        }
        if (css[rule].selectorText == null) {
          continue
        }
        getMatches(css[rule].selectorText)
      }
    }

    function getCSS(sheet) {
      if (sheet.href) {
        var RELATIVE = /^[\w\.]+[^:]*$/;
        var docURL = String(window.location);
        var href = (RELATIVE.test(sheet.href)) ? (docURL.slice(0, docURL.lastIndexOf("/") + 1) + sheet.href) : sheet.href;
        try {
          $.ajax({
            url: href,
            success: function (response) {
              getMatches(response)
            }
          })
        } catch (err) {}
      } else {
        if (sheet.cssText) {
          getMatches(sheet.cssText)
        } else {
          ruleIterator(sheet)
        }
      }
    }
    if (options.manualSelectors) {
      getMatches(options.manualSelectors)
    }
    if (!options.manualSelectors || options.forceStylesheetParsing) {
      if (jQuery.browser.safari && document.readyState != "complete") {
        setTimeout(arguments.callee, 100);
        return
      }
      for (stylesheet = 0; stylesheet < document.styleSheets.length; stylesheet++) {
        try {
          getCSS(document.styleSheets[stylesheet])
        } catch (err) {}
      }
    }
  }
})(jQuery);

function css_browser_selector(u) {
  var ua = u.toLowerCase(),
      is = function (t) {
      return ua.indexOf(t) > -1
      },
      g = 'gecko',
      w = 'webkit',
      s = 'safari',
      o = 'opera',
      h = document.getElementsByTagName('html')[0],
      b = [(!(/opera|webtv/i.test(ua)) && /msie\s(\d)/.test(ua)) ? ('ie ie' + RegExp.$1) : is('firefox/2') ? g + ' ff2' : is('firefox/3.5') ? g + ' ff3 ff3_5' : is('firefox/3') ? g + ' ff3' : is('gecko/') ? g : is('opera') ? o + (/version\/(\d+)/.test(ua) ? ' ' + o + RegExp.$1 : (/opera(\s|\/)(\d+)/.test(ua) ? ' ' + o + RegExp.$2 : '')) : is('konqueror') ? 'konqueror' : is('chrome') ? w + ' chrome' : is('iron') ? w + ' iron' : is('applewebkit/') ? w + ' ' + s + (/version\/(\d+)/.test(ua) ? ' ' + s + RegExp.$1 : '') : is('mozilla/') ? g : '', is('j2me') ? 'mobile' : is('iphone') ? 'iphone' : is('ipod') ? 'ipod' : is('mac') ? 'mac' : is('darwin') ? 'mac' : is('webtv') ? 'webtv' : is('win') ? 'win' : is('freebsd') ? 'freebsd' : (is('x11') || is('linux')) ? 'linux' : '', 'js'];
  c = b.join(' ');
  h.className += ' ' + c;
  return c
};
css_browser_selector(navigator.userAgent);

jQuery(document).ready(function () {
  ZebraTables();
  ZebraUL();
  BlurFocusText();
  jQuery(function () {
    var tabContainers = jQuery("div.tabs > div");
    jQuery("div.tabs ul.tabNavigation a").click(function () {
      tabContainers.hide().filter(this.hash).fadeIn("slow");
      jQuery("div.tabs ul.tabNavigation a").removeClass("selected");
      jQuery(this).addClass("selected");
      return false
    }).filter(":first").click()
  });
  jQuery('div.header-menus ul li#current a').load(function () {
    Cufon.replace(this, {
      color: '-linear-gradient(#003E67, #003E67)'
    });
  });
  jQuery(".header-menus ul li").hover(function () {
    Cufon.replace(jQuery(this).find('a'), {
      color: '-linear-gradient(#004D78, #004D78)'
    });
  }, function () {
      Cufon.replace(jQuery(this).find('a'), {
        color: '-linear-gradient(white, white)'
      });
  });
  Cufon.replace('.header-4 .sec-right h3', {
    color: '-linear-gradient(#4E9B06, #438305)'
  });
  Cufon.replace('.box-inner .b1-content .col-left h4, .box-inner .col-right h3', {
    textShadow: '#595959 1px 1px'
  });
  jQuery("a[rel=external]").each(function () {
    jQuery(this).attr('target', '_blank');
  })
  try {
    jQuery(".case-images a").fancybox({
      transitionIn: 'elastic',
      transitionOut: 'elastic',
			overlayOpacity: 0.9,
			overlayColor: '#000000'
    });
		jQuery("ul.image-lists li .images a").fancybox({
			transitionIn: 'elastic',
			transitionOut: 'elastic',
			overlayOpacity: 0.9,
			overlayColor: '#000000'
    });
    jQuery(".box-industry-type .c30r a").fancybox({
			transitionIn: 'elastic',
			transitionOut: 'elastic',
			overlayOpacity: 0.9,
			overlayColor: '#000000'
    });
    jQuery("a#inline").fancybox({
			transitionIn: 'elastic',
			transitionOut: 'elastic',
			overlayOpacity: 0.9,
			overlayColor: '#000000',
      width: '560'
    })
  } catch (err) {};
  jQuery("a#slide-toggle").toggle(function () {
    jQuery('#slider #slider-content').slideDown('slow');
  }, function () {
    jQuery('#slider #slider-content').slideUp('slow');
  })
});
