// JavaScript Document
function mycarousel_initCallback(carousel,state) {
	jQuery('.jcarousel-control a').bind('click', function() {
		carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
		return false;
	});

	jQuery('.jcarousel-scroll select').bind('change', function() {
		carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
		return false;
	});

	jQuery('#mycarousel-next').bind('click', function() {
		carousel.next();
		return false;
	});

	jQuery('#mycarousel-prev').bind('click', function() {
		carousel.prev();
		return false;
	});
};


jQuery(function(){
  jQuery(".megamenu").megamenu({ 'justify':'right' });
});


jQuery(document).ready(function() {	
	function staticNav() {
        var sidenavHeight1 = $("#history").height(); //Get height of sidenav
        var sidenavHeight2 = $("#sharethis").height(); //Get height of sidenav
        var sidenavHeight3 = $("#livechatside").height(); //Get height of sidenav
        var sidenavHeight4 = $("#feedbackside").height(); //Get height of sidenav
        var winHeight = $(window).height(); //Get height of viewport
        var browserIE6 = (navigator.userAgent.indexOf("MSIE 6")>=0) ? true : false; //Check for IE6

        if (browserIE6) { //if IE6...
            $("#history").css({'position' : 'absolute'});  //reset the sidenav to be absolute
            $("#sharethis").css({'position' : 'absolute'});  //reset the sidenav to be absolute
            $("#livechatside").css({'position' : 'absolute'});  //reset the sidenav to be absolute
            $("#feedbackside").css({'position' : 'absolute'});  //reset the sidenav to be absolute
        } else { //if not IE6...
            $("#history").css({'position' : 'fixed'}); //reset the sidenav to be fixed
            $("#sharethis").css({'position' : 'fixed'}); //reset the sidenav to be fixed
            $("#livechatside").css({'position' : 'fixed'}); //reset the sidenav to be fixed
            $("#feedbackside").css({'position' : 'fixed'}); //reset the sidenav to be fixed
        }

        if (sidenavHeight1 > winHeight) { //If sidenav is taller than viewport...
            $("#history").css({'position' : 'static'}); //switch the fixed positioning to static. Say good bye to sticky nav!
        }

        if (sidenavHeight2 > winHeight) { //If sidenav is taller than viewport...
            $("#sharethis").css({'position' : 'static'}); //switch the fixed positioning to static. Say good bye to sticky nav!
        }

        if (sidenavHeight3 > winHeight) { //If sidenav is taller than viewport...
            $("#livechatside").css({'position' : 'static'}); //switch the fixed positioning to static. Say good bye to sticky nav!
        }

        if (sidenavHeight4 > winHeight) { //If sidenav is taller than viewport...
            $("#feedbackside").css({'position' : 'static'}); //switch the fixed positioning to static. Say good bye to sticky nav!
        }
    }

    staticNav(); //Execute function on load

    $(window).resize(function () { //Each time the viewport is adjusted/resized, execute the function
        staticNav();
    });

	$("#history_icon").qtip({
		content: $("#history_popup").html(),
		position: {
			corner: {
				target: 'rightMiddle',
				tooltip: 'leftMiddle'
			}
		},
		style: { 
			tip: 'leftMiddle',
			name: 'light',
			border: {
				radius: 5
			}
		},
		hide: {
			fixed: true
		}
	});

	$("#sharethis_icon").qtip({
		content: $("#sharethis_popup").html(),
		position: {
			corner: {
				target: 'rightMiddle',
				tooltip: 'leftMiddle'
			}
		},
		style: { 
			tip: 'leftMiddle',
			name: 'light',
			width: 142,
			border: {
				radius: 5
			}
		},
		hide: {
			fixed: true
		}
	});
	  
	if(getEl('websites3')) $("#websites3").msDropDown();
});

$(function() {

	// if the function argument is given to overlay,
	// it is assumed to be the onBeforeLoad event listener
	$('a[rel="#loginOverlay"]').overlay({
		top: 90,
		mask: {
			color: '#333',
			loadSpeed: 200,
			opacity: 0.8,
			closeOnClick: false
		},
		onBeforeLoad: function() {
			var wrap = this.getOverlay().find(".contentWrap");
			wrap.load(this.getTrigger().attr("name"));
		}

	});
});

$(window).load(function() {
	if(document.getElementById('before_carousel')){ $('.top_va').insertAfter($('#before_carousel'));}
});
