/**
 * jQuery Opacity Rollover plugin
 *
 * Copyright (c) 2009 Trent Foley (http://trentacular.com)
 * Licensed under the MIT License:
 *   http://www.opensource.org/licenses/mit-license.php
 */
(function($) {
    var defaults = {
        mouseOutOpacity:   0.67,
        mouseOverOpacity:  1.0,
        fadeSpeed:         'fast',
        exemptionSelector: '.selected'
    };

    $.fn.opacityrollover = function(settings) {
        // Initialize the effect
        $.extend(this, defaults, settings);

        var config = this;

        function fadeTo(element, opacity) {
            var $target = $(element);

            if (config.exemptionSelector)
                    $target = $target.not(config.exemptionSelector);

            $target.fadeTo(config.fadeSpeed, opacity);
        }

        this.css('opacity', this.mouseOutOpacity)
            .hover(
                function () {
                        fadeTo(this, config.mouseOverOpacity);
                },
                function () {
                        fadeTo(this, config.mouseOutOpacity);
                });

        return this;
    };
})(jQuery);

/*
 * jQuery corner plugin: simple corner rounding
 * Examples and documentation at: http://jquery.malsup.com/corner/
 * version 2.10 (05-MAY-2010)
 * Requires jQuery v1.3.2 or later
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * Authors: Dave Methvin and Mike Alsup
 */
(function(c){var a=document.createElement("div").style;var h=a.MozBorderRadius!==undefined;var j=a.WebkitBorderRadius!==undefined;var e=a.borderRadius!==undefined||a.BorderRadius!==undefined;var d=document.documentMode||0;var l=c.browser.msie&&((c.browser.version<8&&!d)||d<8);var i=c.browser.msie&&(function(){var n=document.createElement("div");try{n.style.setExpression("width","0+0");n.style.removeExpression("width")}catch(m){return false}return true})();function g(m,n){return parseInt(c.css(m,n))||0}function k(m){var m=parseInt(m).toString(16);return(m.length<2)?"0"+m:m}function b(o){while(o){var m=c.css(o,"backgroundColor");if(m&&m!="transparent"&&m!="rgba(0, 0, 0, 0)"){if(m.indexOf("rgb")>=0){var n=m.match(/\d+/g);return"#"+k(n[0])+k(n[1])+k(n[2])}return m}if(o.nodeName.toLowerCase()=="html"){break}o=o.parentNode}return"#ffffff"}function f(o,m,n){switch(o){case"round":return Math.round(n*(1-Math.cos(Math.asin(m/n))));case"cool":return Math.round(n*(1+Math.cos(Math.asin(m/n))));case"sharp":return Math.round(n*(1-Math.cos(Math.acos(m/n))));case"bite":return Math.round(n*(Math.cos(Math.asin((n-m-1)/n))));case"slide":return Math.round(n*(Math.atan2(m,n/m)));case"jut":return Math.round(n*(Math.atan2(n,(n-m-1))));case"curl":return Math.round(n*(Math.atan(m)));case"tear":return Math.round(n*(Math.cos(m)));case"wicked":return Math.round(n*(Math.tan(m)));case"long":return Math.round(n*(Math.sqrt(m)));case"sculpt":return Math.round(n*(Math.log((n-m-1),n)));case"dogfold":case"dog":return(m&1)?(m+1):n;case"dog2":return(m&2)?(m+1):n;case"dog3":return(m&3)?(m+1):n;case"fray":return(m%2)*n;case"notch":return n;case"bevelfold":case"bevel":return m+1}}c.fn.corner=function(m){if(this.length==0){if(!c.isReady&&this.selector){var n=this.selector,o=this.context;c(function(){c(n,o).corner(m)})}return this}return this.each(function(v){var u=c(this);var D=[u.attr(c.fn.corner.defaults.metaAttr)||"",m||""].join(" ").toLowerCase();var K=/keep/.test(D);var C=((D.match(/cc:(#[0-9a-f]+)/)||[])[1]);var p=((D.match(/sc:(#[0-9a-f]+)/)||[])[1]);var G=parseInt((D.match(/(\d+)px/)||[])[1])||10;var E=/round|bevelfold|bevel|notch|bite|cool|sharp|slide|jut|curl|tear|fray|wicked|sculpt|long|dog3|dog2|dogfold|dog/;var r=((D.match(E)||["round"])[0]);var s=/dogfold|bevelfold/.test(D);var q={T:0,B:1};var z={TL:/top|tl|left/.test(D),TR:/top|tr|right/.test(D),BL:/bottom|bl|left/.test(D),BR:/bottom|br|right/.test(D)};if(!z.TL&&!z.TR&&!z.BL&&!z.BR){z={TL:1,TR:1,BL:1,BR:1}}if(c.fn.corner.defaults.useNative&&r=="round"&&(e||h||j)&&!C&&!p){if(z.TL){u.css(e?"border-top-left-radius":h?"-moz-border-radius-topleft":"-webkit-border-top-left-radius",G+"px")}if(z.TR){u.css(e?"border-top-right-radius":h?"-moz-border-radius-topright":"-webkit-border-top-right-radius",G+"px")}if(z.BL){u.css(e?"border-bottom-left-radius":h?"-moz-border-radius-bottomleft":"-webkit-border-bottom-left-radius",G+"px")}if(z.BR){u.css(e?"border-bottom-right-radius":h?"-moz-border-radius-bottomright":"-webkit-border-bottom-right-radius",G+"px")}return}var H=document.createElement("div");c(H).css({overflow:"hidden",height:"1px",minHeight:"1px",fontSize:"1px",backgroundColor:p||"transparent",borderStyle:"solid"});var N={T:parseInt(c.css(this,"paddingTop"))||0,R:parseInt(c.css(this,"paddingRight"))||0,B:parseInt(c.css(this,"paddingBottom"))||0,L:parseInt(c.css(this,"paddingLeft"))||0};if(typeof this.style.zoom!=undefined){this.style.zoom=1}if(!K){this.style.border="none"}H.style.borderColor=C||b(this.parentNode);var F=c(this).outerHeight();for(var I in q){var y=q[I];if((y&&(z.BL||z.BR))||(!y&&(z.TL||z.TR))){H.style.borderStyle="none "+(z[I+"R"]?"solid":"none")+" none "+(z[I+"L"]?"solid":"none");var O=document.createElement("div");c(O).addClass("jquery-corner");var B=O.style;y?this.appendChild(O):this.insertBefore(O,this.firstChild);if(y&&F!="auto"){if(c.css(this,"position")=="static"){this.style.position="relative"}B.position="absolute";B.bottom=B.left=B.padding=B.margin="0";if(i){B.setExpression("width","this.parentNode.offsetWidth")}else{B.width="100%"}}else{if(!y&&c.browser.msie){if(c.css(this,"position")=="static"){this.style.position="relative"}B.position="absolute";B.top=B.left=B.right=B.padding=B.margin="0";if(i){var L=g(this,"borderLeftWidth")+g(this,"borderRightWidth");B.setExpression("width","this.parentNode.offsetWidth - "+L+'+ "px"')}else{B.width="100%"}}else{B.position="relative";B.margin=!y?"-"+N.T+"px -"+N.R+"px "+(N.T-G)+"px -"+N.L+"px":(N.B-G)+"px -"+N.R+"px -"+N.B+"px -"+N.L+"px"}}for(var J=0;J<G;J++){var x=Math.max(0,f(r,J,G));var M=H.cloneNode(false);M.style.borderWidth="0 "+(z[I+"R"]?x:0)+"px 0 "+(z[I+"L"]?x:0)+"px";y?O.appendChild(M):O.insertBefore(M,O.firstChild)}if(s&&c.support.boxModel){if(y&&l){continue}for(var P in z){if(!z[P]){continue}if(y&&(P=="TL"||P=="TR")){continue}if(!y&&(P=="BL"||P=="BR")){continue}var A={position:"absolute",border:"none",margin:0,padding:0,overflow:"hidden",backgroundColor:H.style.borderColor};var t=c("<div/>").css(A).css({width:G+"px",height:"1px"});switch(P){case"TL":t.css({bottom:0,left:0});break;case"TR":t.css({bottom:0,right:0});break;case"BL":t.css({top:0,left:0});break;case"BR":t.css({top:0,right:0});break}O.appendChild(t[0]);var Q=c("<div/>").css(A).css({top:0,bottom:0,width:"1px",height:G+"px"});switch(P){case"TL":Q.css({left:G});break;case"TR":Q.css({right:G});break;case"BL":Q.css({left:G});break;case"BR":Q.css({right:G});break}O.appendChild(Q[0])}}}}})};c.fn.uncorner=function(){if(e||h||j){this.css(e?"border-radius":h?"-moz-border-radius":"-webkit-border-radius",0)}c("div.jquery-corner",this).remove();return this};c.fn.corner.defaults={useNative:true,metaAttr:"data-corner"}})(jQuery);

/*
 * jQuery history plugin
 *
 * sample page: http://www.mikage.to/jquery/jquery_history.html
 *
 * Copyright (c) 2006-2009 Taku Sano (Mikage Sawatari)
 * Copyright (c) 2010 Takayuki Miwa
 * Licensed under the MIT License:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Modified by Lincoln Cooper to add Safari support and only call the callback once during initialization
 * for msie when no initial hash supplied.
 */
(function(e){var f={put:function(h,g){(g||window).location.hash=encodeURIComponent(h)},get:function(h){var g=((h||window).location.hash).replace(/^#/,"");return e.browser.fx?g:decodeURIComponent(g)}};var d={id:"__jQuery_history",init:function(){var g='<iframe id="'+this.id+'" style="display:none" src="javascript:false;" />';e("body").prepend(g);return this},_document:function(){return e("#"+this.id)[0].contentWindow.document},put:function(h){var g=this._document();g.open();g.close();f.put(h,g)},get:function(){return f.get(this._document())}};var b={appState:undefined,callback:undefined,init:function(g){},check:function(){},load:function(g){}};e.history=b;var a={init:function(h){b.callback=h;var g=f.get();b.appState=g;if(g){b.callback(g)}setInterval(b.check,100)},check:function(){var g=f.get();if(g!=b.appState){b.appState=g;b.callback(g)}},load:function(g){if(g!=b.appState){f.put(g);b.appState=g;b.callback(g)}}};var c={init:function(h){b.callback=h;var g=f.get();b.appState=g;d.init().put(g);if(g){b.callback(g)}setInterval(b.check,100)},check:function(){var g=d.get();if(g!=b.appState){f.put(g);b.appState=g;b.callback(g)}},load:function(g){if(g!=b.appState){f.put(g);d.put(g);b.appState=g;b.callback(g)}}};if(e.browser.msie&&(e.browser.version<8||document.documentMode<8)){e.extend(b,c)}else{e.extend(b,a)}})(jQuery);

/*
Sliding Labels 3.0

This is the official plugin version of Sliding Labels.
It is open source code by Tim Wright of CSSKarma.com
Use as you see fit, I'd like it if you kept this in
the code, but basically share it and don't be a jerk.

Support:
http://www.csskarma.com/blog/sliding-labels-plugin

Version: 2 - added textarea functionality
Version: 3 - added axis parameter
           - added speed parameter
           - removed color parameter, as it should be define in the CSS
           - added position:relative to wrapping element
           - coverted to jQuery plugin
*/
(function($){$.fn.slidinglabels=function(options){var defaults={topPosition:"5px",leftPosition:"5px",axis:"x",speed:"fast"};var options=$.extend(defaults,options);var itemwrapper=this.children(".slider");var labels=itemwrapper.children("label");return labels.each(function(){obj=$(this);var parent=obj.parents(".slider");parent.css({position:"relative"});obj.css({position:"absolute",top:defaults.topPosition,left:defaults.leftPosition,display:"inline","z-index":99});var inputval=$(this).next().val();var labelwidth=$(this).width();var labelmove=labelwidth+5+"px";var labelheight=$(this).height();if(inputval!==""){if(defaults.axis=="x"){obj.stop().animate({left:"-"+labelmove},1)}else{if(defaults.axis=="y"){obj.stop().animate({top:"-"+labelheight},1)}}}$("input, textarea").focus(function(){var label=$(this).prev("label");var width=label.width();var height=label.height();var adjust=width+5+"px";var adjustUp=height+"px";var value=$(this).val();if(value==""){if(defaults.axis=="x"){label.stop().animate({left:"-"+adjust},defaults.speed)}else{if(defaults.axis=="y"){label.stop().animate({top:"-"+adjustUp},defaults.speed)}}}else{if(defaults.axis=="x"){label.css({left:"-"+adjust})}else{if(defaults.axis=="y"){label.css({top:"-"+adjustUp})}}}}).blur(function(){var label=$(this).prev("label");var value=$(this).val();if(value==""){if(defaults.axis=="x"){label.stop().animate({left:defaults.leftPosition},defaults.speed)}else{if(defaults.axis=="y"){label.stop().animate({top:defaults.topPosition},defaults.speed)}}}})})}})(jQuery);

function removeCbox()
{
    $.colorbox.remove();
}

function popvideo1(clicked)
{
    var tmp_yt_img = $('<img id="ytfavimg" src="http://youtube.com/favicon.ico" />');    
    tmp_yt_img.load(function()
    {
        /* has access to youtube */
        
        $.getScript('/newincludes/js/jquery.colorbox-min.js', function() { 
            $("#popvideo1_a").colorbox({iframe:true, innerWidth:560, innerHeight:349, open: true, onClosed: removeCbox });
        });
        
        if (clicked)
        {
            try { 
                _gaq.push(['_trackPageview', '/video/home-youtube-1']);
                /* _gaq.push(['_trackEvent', 'Videos', 'Click', 'Intro Video 1']); */
            }
            catch (e) {}
        }
    }).error(function(){
        /* does not have access to youtube */
        /* alert('No Access to Youtube'); */
    });
}

function updatecnt()
{
    var sendReq = front_getXmlHttpRequestObject();
    sendReq.open("GET", '/updatecnt.php', true);
    sendReq.onreadystatechange = function()
    {
        if(sendReq.readyState==4)
        {}
    };
    sendReq.send('');
    return false;
}

var currenttab = '';
var currentmenu = '';
function navmenu()
{
    var parent = $('.nav-new > li');
    currenttab = $('.nav-new-current');
    currentmenu = currenttab.attr("href").substring(1);

    $(parent).children("a").each(function()
    {
        var mytab = $(this).attr("href").substring(1);
        if (mytab != currentmenu) { $('#t_'+mytab).css('display','none'); } // only show current tab on load

        $(this).click(function()
        {
            if (mytab == currentmenu) { return true; } // no double events

            var menutext = $(this).attr('title');
            try {
                _gaq.push(['_trackPageview', '/menu/'+menutext]);
                /*_gaq.push(['_trackEvent', 'Menu', 'Click', menutext]);*/
            } catch (e) {}

            $('#t_'+currentmenu).fadeOut('fast',function(){ $('#t_'+mytab).fadeIn('fast'); });

            currenttab.removeClass('nav-new-current');
            $(this).addClass('nav-new-current');
            currenttab = $(this);
            currentmenu = mytab;
            return true; // allow change in address bar
        });
    });
}

function clickmenu(hash)
{
    $('a[href="#'+hash+'"]').click();
}

function navtestimony()
{
    $(".testimony").each(function()
    {
        var mynum = $(this).attr("href").substring(2);

        $(this).click(function(event)
        {
            event.preventDefault(); // prevent changes to location

            var menutext = $(this).attr('title');
            try { _gaq.push(['_trackEvent', 'Testimonial', 'Click', menutext]); } catch (e) {}

            $('.sc_menu_a_current').removeClass('sc_menu_a_current');
            $(this).addClass('sc_menu_a_current');

            $('#testimony_text').html('Loading '+menutext+'...');
            $.get('/testimony2.php?tnum='+mynum, function(data) { $('#testimony_text').fadeOut('fast',function() { $('#testimony_text').html(data).fadeIn('fast'); externalLinks(); }) });
        });
    });
}

function showEM(dom,user,where)
{
    if (where.className == 'reva')
    {
        return false;
    }

    where.className = 'reva';
    orig = dom+'@'+user;
    text = '';
    for (i = 0; i <= orig.length; i++)
    {
        text = orig.substring(i, i+1) + text;
    }
    where.href = "mailto:"+text;
    where.innerHTML = text;

    return false;
}

function externalLinks()
{
    $('a[rel*=external]').click( function() {
        window.open( $(this).attr('href') );
        return false;
    });
}

function clickDemo(me)
{
    if (typeof hs=="undefined")
    {
        $.getScript('/highslide/highslide-with-html.packed.swfobject.js', function() { clickDemo2(me); });
    }
    else { clickDemo2(me); }
}

function clickDemo2(me)
{
    hs.graphicsDir = '/highslide/graphics/';
    hs.outlineType = 'rounded-white';
    hs.outlineWhileAnimating = true;
    hs.allowSizeReduction = false;
    hs.preserveContent = false;
    var so = new SWFObject("/images/ehr_demo.swf", "my-flash", "760", "475", "8", "#FFFFFF");
    so.addParam("wmode", "transparent");

    try { _gaq.push(['_trackEvent', 'Buttons', 'Click', 'View Old Flash Demo']); } catch (e) {}

    hs.htmlExpand(me, { swfObject: so } );
}

function contactform()
{
    $('#comment2').attr('name','comment');
    $('#contactform').attr('action','').submit();
    return false;
}

function featureform()
{
    $('#feature2').attr('name','feature');
    $('#featureform').attr('action','').submit();
    return false;
}

function dotestslide()
{
    //Get our elements for faster access and set overlay width
    var div = $('div.sc_menu');
    var ul = $('ul.sc_menu');
    var ulPadding = 15;

    //Remove scrollbars
    div.css({overflow: 'hidden'});

    //Find last image container
    var lastLi = ul.find('li:last-child');

    //When user move mouse over menu
    div.mousemove(function(e){
            //As images are loaded ul width increases,
            //so we recalculate it each time
            var divWidth = div.width();
            var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;
            var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
            div.scrollLeft(left);
    });
}

var moved = false;
$(document).ready(function() {
    try {
        $('.cornerme').corner("round 8px").parent().css('padding', '1px').corner("round 6px")
        $('.topcorner').corner("top round 8px");
        $('#header-new').corner("bottom round 8px");
    } catch(e) {}

    try {
        //$('#viewdemo1').click(function(event) { event.preventDefault(); clickDemo(this); return false; });
        $('#viewdemoimg').hover(function(){ $(this).attr('src','/newimages/view-demo-over.png'); },function(){ $(this).attr('src','/newimages/view-demo.png'); });
        $('#startnowimg').hover(function(){ $(this).attr('src','/newimages/start-now-over.png'); },function(){ $(this).attr('src','/newimages/start-now-norm.png'); });
    } catch(e) {}

    try {
        if (typeof stateregion != 'undefined') {
            $('#statesel').val(stateregion);
            $('#statesel').change(function(){ $('#stateselfrm').submit(); });
        }
    } catch(e) {}

    try { navmenu(); } catch (e) {}

    try {
        var hash = window.location.hash;
        $.history.init(function (hash)
        {
            if(hash) { clickmenu(hash); }
        });
    } catch(e) {}

    try {
        $(document).mousemove(function() {
            if (moved == false)
            {
                moved = true;
                $(document).unbind('mousemove');

                $('.mmimg').each(function() { $(this).attr('src',$(this).attr('data-src')); });
                $('.mmimg').show();

                /*
                $.getScript('https://www.google.com/jsapi', function() {
                    $.getScript('https://static.plupper.com/js/plupper.js', function() {
                        plupper.init("effortlesshr@plupper.com");
                        plupper.showSideBadge("right", "30%");
                        plupper.enableCobrowsing();
                    });
                });
                */

                /*
                $.getScript('http://www.effortlesshr.com/clickheat/js/clickheat-jquery.js', function() {
                });
                */
            }
        });
    } catch(e) {}

    try {
        $('#contactform').slidinglabels({
            topPosition  : '5px',  // how far down you want each label to start
            leftPosition : '5px',  // how far left you want each label to start
            axis         : 'x',    // can take 'x' or 'y' for slide direction
            speed        : 'fast'  // can take 'fast', 'slow', or a numeric value
        });

        $('#featureform').slidinglabels({
            topPosition  : '5px',  // how far down you want each label to start
            leftPosition : '5px',  // how far left you want each label to start
            axis         : 'x',    // can take 'x' or 'y' for slide direction
            speed        : 'fast'  // can take 'fast', 'slow', or a numeric value
        });
    } catch(e) {}

    try { dotestslide(); } catch(e) {}
    try { navtestimony(); } catch(e) {}
    try { externalLinks(); } catch(e) {}
    
    $('#popvideo1_a').click(function(e){ 
        e.preventDefault();
        e.stopPropagation();
        popvideo1(true);
        return false;
    });
});
