// UMA v2 Javascript Document
$ = jQuery.noConflict();
$ = jQuery;

// Back to top footer button
$(function(){$.fn.scrollToTop=function(){$(this).hide().removeAttr("href");if($(window).scrollTop()!="0"){$(this).fadeIn("fast")}var scrollDiv=$(this);$(window).scroll(function(){if($(window).scrollTop()=="0"){$(scrollDiv).fadeOut("fast")}else{$(scrollDiv).fadeIn("fast")}});$(this).click(function(){$("html, body").animate({scrollTop:0},"slow")})}});
$(function() {
	$("#toTop").scrollToTop();
});

$(document).ready(function() {
	$("div.panel_button").click(function(){
		$("div#panel").animate({
			height: "384px"
		}).animate({
			height: "350px"
		}, "fast");
		$("div#shade").css({
			display: "block"
		});
		$("div.panel_button").toggle();
	});	
	
   $("div#hide_button").click(function(){
		$("div#panel").animate({
			height: "0px"
		}, "fast");
		$("div#shade").css({
			display: "none"
		});
   });
});

$(document).ready(function() {
	$('#metrics-analysis').scrollTo( { top: 300, left:'+=200' }, { axis:'xy', offset:-20 });
});

$(document).ready(function() {
	if($('#em-seo-wrapper').length > 0){ //If element exists
		$('#em-seo-wrapper').cycle({
			fx : 'fade',
			speed :  250, 
			timeout : 0,
			pause : 1,
			random : false,
			cleartype :  1, // enable cleartype corrections
			cleartypeNoBg: true,
			pager : '#em-seo-wrapper-pager',
			pagerAnchorBuilder: function(idx, slide) {
				if (idx == 0) {
						return '<div class="email-marketing"><a href="#">Email Marketing</a></div>';
				}
				if (idx == 1) {
						return '<div class="search-engine-optimization"><a href="#">SEO &amp; Online Marketing</a></div>';
				}
				else {
                        return '' + (idx + 1) + '';
                }

			}

		});
	}
	
	if($('#em-slider').length > 0){ //If element exists
		$('#em-slider').cycle({
			fx : 'scrollHorz',
			speed :  400, 
			timeout : 0,
			pause : 1,
			random : false,
			cleartype :  1, // enable cleartype corrections
			cleartypeNoBg: true,
			next : '#em-slider-next',
			prev : '#em-slider-previous',
			pager : '#em-slider-nav-pager',
			pagerAnchorBuilder: function(idx, slide) {
				if (idx == 0) {
						return '<li class="one"><a href="#">Overview</a></li>';
				}
				if (idx == 1) {
						return '<li class="two"><a href="#">Dashboard</a></li>';
				}
				if (idx == 2) {
						return '<li class="three"><a href="#">Contact Lists</a></li>';
				}
				if (idx == 3) {
						return '<li class="four"><a href="#">Email Campaigns</a></li>';
				}
				if (idx == 4) {
						return '<li class="five"><a href="#">Statistics</a></li>';
				}
				if (idx == 5) {
						return '<li class="six"><a href="#">Autoresponders &amp; Triggers</a></li>';
				}
				if (idx == 6) {
						return '<li class="seven"><a href="#">Advanced Marketing</a></li>';
				}
				else {
                        return '' + (idx + 1) + '';
                }

			}
		});
	}
	
	if($('#seo-info').length > 0){ //If element exists
		$('#seo-info').cycle({
			fx : 'fade',
			speed :  500, 
			timeout : 0,
			pause : 1,
			random : false,
			cleartype :  1, // enable cleartype corrections
			cleartypeNoBg: true,
			pager : '#seo-info-nav-pager',
			pagerAnchorBuilder: function(idx, slide) {
				if (idx == 0) {
						return '<li class="one"><a href="#">Website Conversion</a></li>';
				}
				if (idx == 1) {
						return '<li class="two"><a href="#">Pay Per Click</a></li>';
				}
				if (idx == 2) {
						return '<li class="three"><a href="#">Search Engine Optimization</a></li>';
				}
				if (idx == 3) {
						return '<li class="four"><a href="#">Social Media/Networking</a></li>';
				}
				if (idx == 4) {
						return '<li class="five"><a href="#">SEO Optimization Websites</a></li>';
				}
				if (idx == 5) {
						return '<li class="six"><a href="#">Website Advertising</a></li>';
				}
				else {
                        return '' + (idx + 1) + '';
                }

			}
		});
	}
	
	if($('#portfolio-slider').length > 0){ //If element exists
		$('#portfolio-slider').cycle({
			fx:        'cover',
			delay:    -800,
			before: function(curr, next, opts) {
				opts.animOut.opacity = 0;
			},
			speed :  500, 
			timeout : 0,
			pause : 1,
			random : false,
			cleartype :  1, // enable cleartype corrections
			cleartypeNoBg: true,
			next : '#portfolio-slider-next',
			prev : '#portfolio-slider-previous',
			pager : '#portfolio-slider-pager',
			pagerAnchorBuilder: function(idx, slide) {
				if (idx == 0) {
						return '<li class="pagination"><a href="#"></a></li>';
				}
				else {
                        return '<li class="pagination"><a href="#"></a></li>';
                }

			}

		});
	}
});

this.imagePreview = function(){	
	/* CONFIG */
		
		xOffset = 10;
		yOffset = 30;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ this.href +"' alt='Image preview' />"+ c +"</p>");								 
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};


// starting the script on page load
$(document).ready(function(){
	imagePreview();
});

// Div switch
var ie = (document.all) ? true : false;
function hideID(objID){
	var element = (ie) ? document.all(objID) : document.getElementById(objID);
	element.style.display="none"
}
function showID(objID){
	var element = (ie) ? document.all(objID) : document.getElementById(objID);
	element.style.display="block"
}

// Tipsy Content Pop-up
$(document).ready(function() {
	$('#comparison, #comparison-2, #comparison-3, #comparison-4, #comparison-5, #comparison-6, #comparison-7, #comparison-8, #comparison-9, #comparison-10, #comparison-11, #comparison-12, #comparison-13, #comparison-14, #comparison-15, #comparison-16, #comparison-17, #comparison-18, #comparison-19, #comparison-20, #comparison-21, #comparison-22, #comparison-23, #comparison-24, #comparison-25, #comparison-26, #comparison-27, #comparison-28, #comparison-29, #comparison-30, #comparison-31, #comparison-32, #comparison-33, #comparison-34, #comparison-35, #comparison-36, #comparison-37, #comparison-38, #comparison-39, #comparison-40').tipsy({
		fade: true,
		delayIn: 300,
		delayOut: 400,
		gravity: 'w'
	});
});

$(document).ready(function() {
	$("#fancybox, #comparison-fancybox-design-basic, #comparison-fancybox-design-plus, #comparison-fancybox-design-premium, #comparison-fancybox-design-max, #core-principles, .client-login").fancybox({
		'transitionIn'			: 	'fade',
		'transitionOut'			: 	'fade',
		'easingIn'      		: 	'easeOutBack',
		'easingOut'     		: 	'easeInBack',
		'speedIn'				:	400,
		'speedOut'				:	500,
		'hideOnOverlayClick'	:	false,
		'padding'				: 	0,
		'showCloseButton'		:	true,
		'overlayColor'			:	'#181714',
		'overlayOpacity'		:	'0.4',
		'titleShow'				: 	false,
		'centerOnScroll'		:	true
	});
	$(".client-login a, .client-login").fancybox({
		'transitionIn'			: 	'fade',
		'transitionOut'			: 	'fade',
		'easingIn'      		: 	'easeOutBack',
		'easingOut'     		: 	'easeInBack',
		'width'					:	'95%',
		'height'				:	'95%',
        'autoScale'     		:	false,
        'transitionIn'			:	'none',
		'transitionOut'			:	'none',
		'centerOnScroll'		:	true,
		'hideOnOverlayClick'	:	false,
		'overlayColor'			:	'#181714',
		'overlayOpacity'		:	'0.4',
		'padding'				: 	0,
		'type'					:	'iframe'
	});
});

// Bubble info
$(function () {
  $('.bubbleInfo').each(function () {
    // options
    var distance = 10;
    var time = 500;
    var hideDelay = 250;

    var hideDelayTimer = null;

    // tracker
    var beingShown = false;
    var shown = false;
    
    var trigger = $('.bubble-trigger', this);
    var popup = $('.bubble-popup', this).css('opacity', 0);

    // set the mouseover and mouseout on both element
    $([trigger.get(0), popup.get(0)]).mouseover(function () {
      // stops the hide event if we move from the trigger to the popup element
      if (hideDelayTimer) clearTimeout(hideDelayTimer);

      // don't trigger the animation again if we're being shown, or already visible
      if (beingShown || shown) {
        return;
      } else {
        beingShown = true;

        // reset position of popup box
        popup.css({
		  top: -110,
		  left: -28,
          display: 'block' // brings the popup back in to view
        })

        // (we're using chaining on the popup) now animate it's opacity and position
        .animate({
          top: '-=' + distance + 'px',
          opacity: 1
        }, time, 'swing', function() {
          // once the animation is complete, set the tracker variables
          beingShown = false;
          shown = true;
        });
      }
    }).mouseout(function () {
      // reset the timer if we get fired again - avoids double animations
      if (hideDelayTimer) clearTimeout(hideDelayTimer);
      
      // store the timer so that it can be cleared in the mouseover if required
      hideDelayTimer = setTimeout(function () {
        hideDelayTimer = null;
        popup.animate({
          top: '-=' + distance + 'px',
          opacity: 0
        }, time, 'swing', function () {
          // once the animate is complete, set the tracker variables
          shown = false;
          // hide the popup entirely after the effect (opacity alone doesn't do the job)
          popup.css('display', 'none');
        });
      }, hideDelay);
    });
  });
});


