jQuery(function($) {
	
	$('.slider > div').easySlider({
		auto : true,
		prevId : 'prev',
		prevText : 'Previous',
		nextId : 'next',
		nextText : 'Next',
		continuous : true,
		speed : 2000,
		pause : 4000
	});
	
	$('.our-clients div.our-clients-slider').easySlider({
		continuous : true,
		prevId : 'prevBtn',
		prevText : 'Previous',
		nextId : 'nextBtn',
		nextText : 'Next'
	});
	
	$('#solutions-by-industry > div').easySlider({
		prevId : 'prevBtn',
		prevText : 'Previous',
		nextId : 'nextBtn',
		nextText : 'Next'
	});
	
	$('#solutions-by-category > div').easySlider({
		prevId : 'leftBtn',
		prevText : 'Previous',
		nextId : 'rightBtn',
		nextText : 'Next'
	});
	
	if ($('#tabs.solutions-tabs').length) {
		$('#tabs.solutions-tabs').tabs({
			show: function(event, ui) {
				$('div.sliders > div').hide().filter('#solutions-' + $(ui.tab).attr('href').substr(1)).show();
			}
		});
	} else {
		$("#tabs").tabs();
	}

	$(".customerMoreInfo").hide();
	
	$(".customerShortInfo p.more a").click(function(e) {
		e.preventDefault();
		txt = $(this).text() == "Close" ? "View more" : "Close";
		$(this).text(txt);
		$(this).parents(".type-customer").toggleClass("active")
			.find(".customerMoreInfo").toggle();
	});
	
	$(".clientTestimonials a").click(function(e) {
		e.preventDefault();
		$more = $(this).parent().parent().prev().find("p.more a");
		txt = $more.text() == "Close" ? "View more" : "Close";
		$more.text(txt);
		$more.parents(".type-customer").toggleClass("active")
			.find(".customerMoreInfo").toggle();
	});

	$("#s").val("Search Articles").css("color", "#BCBCBC").focus(function() {
		$(this).css("color", "black");
		if ($(this).val() == "Search Articles") {
			$(this).val("");
		}
	}).blur(function() {
		$(this).css("color", "#BCBCBC");
		if ($(this).val() == "") {
			$(this).val("Search Articles");
		}
	});
	
	var $webinarLink = $('#webinar-download-link');
	if ($webinarLink.length) {
		$webinarLink.appendTo($webinarLink.siblings('.wpcf7'));
	}
	
	if ($('body').is('.single-solutions')) {
		$(".main-navigation li:contains('Solutions'), .main-navigation li:contains('solutions')").addClass('current-menu-item');
	} else if ($('body').is('.single-blog-post')) {
		$(".main-navigation li:contains('Blog'), .main-navigation li:contains('blog')").addClass('current-menu-item');
	}
	
	
	/*
	 * Products sidebar
	 */
	$('div.products-sidebar div.clearfix ul li').bind('click', function(event) {
		event.preventDefault();
		event.stopPropagation();
		window.location = $(this).find('a').attr('href');
	}).find('a').bind('click', function(event) {
		event.preventDefault();
	});
	
	
	// Homepage video
	$('body.home div.what-are-clients-saying div.video a.youtube-video').one('click', function(event) {
		event.preventDefault();
		var $link = $(this).unbind(),
			$image = $link.find('img'),
			$video = $('<iframe src="' + $link.attr('href') + '" frameborder="0" width="' + $image.attr('width') + '" height="' + $image.attr('height') + '"></iframe>'); 
		$link.replaceWith($video);
	});

});

jQuery(window).bind('load', function() {
	
	/*
	 * Social links
	 */
	var $links = '<a class="linkedin" href="http://www.linkedin.com/company/739773?goback=%2Efcs_GLHD_convertro_false_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2_*2&trk=ncsrch_hits">LinkedIn</a> \
		<a class="feedburner" href="http://feeds.feedburner.com/convertro/qAqh">FeedBurner</a> \
		<a class="youtube" href="http://www.youtube.com/user/convertro">Youtube</a> \
		<a class="facebook" href="http://www.facebook.com/MediaAttribution">Facebook</a> \
		<a class="twitter" href="http://twitter.com/#!/convertro">Twitter</a> \
		<g:plusone></g:plusone> \
		<div id="fb-root"></div> \
		<div class="fb-like" data-href="http://www.convertro.com/" data-send="true" data-width="450" data-show-faces="true" data-font="verdana"></div>';
	jQuery('div.footer div.legality div.social-links').append($links);
	
	jQuery.getScript('https://apis.google.com/js/plusone.js');
	
	// from https://developers.facebook.com/docs/reference/javascript/
    window.fbAsyncInit = function() {
        FB.init({
            channelURL : '//www.convertro.com/channel.html', // Channel File
            status     : true, // check login status
            cookie     : true, // enable cookies to allow the server to access the session
            xfbml      : true  // parse XFBML
        });
    };
  
	(function(d, s, id) { 
		var js, fjs = d.getElementsByTagName(s)[0]; 
		if (d.getElementById(id)) {return;} 
		js = d.createElement(s); js.id = id; 
		js.src = "//connect.facebook.net/en_US/all.js";
		fjs.parentNode.insertBefore(js, fjs); 
	}(document, "script", "facebook-jssdk"));
	
});
