/* Author: 

*/

if ($("body.startpage").length)
	removeTwitterLinks(0);

function removeTwitterLinks( part ) {
    if( part == 0 ) {
        setTimeout( function() { removeTwitterLinks( 1 ); }, 1500 );
    } else if( part == 1 ) {
		$("#twtr-widget-1 em").html($("#twtr-widget-1 a.twtr-timestamp"));
		$("#twtr-widget-1 a.twtr-user").first().attr("href", "https://twitter.com/#!/Paxport_AB");
    }
}

$('#mc-embedded-subscribe').click(function () {
	var form = document.createElement("form");
		form.setAttribute("method", "post");
		form.setAttribute("target", "_blank");
		form.setAttribute("action", "http://paxport.us1.list-manage.com/subscribe/post?u=30891e0b975896bf1e2271e17&id=2817757078");

	var hiddenField = document.createElement("input");              
		hiddenField.setAttribute("name", "EMAIL");
		hiddenField.setAttribute("value", $("#mce-EMAIL").val());
		form.appendChild(hiddenField);
		document.body.appendChild(form);    // Not entirely sure if this is necessary                   
		form.submit();
		return false;
}); 

$('#main div.xForm :submit').not('.ie7 #main div.xForm :submit').not('.ie8 #main div.xForm :submit').addClass("button");

//general hover class
$('#main .hover-this').hover(function () {
	if ($(this).find("a:first").attr("href").length) 
		$(this).addClass('hover');
}, function () {
    $(this).removeClass('hover');
});

$('#main .clickable').click(function () {
	var link = $(this).find("a:first");
	if (link.attr("href").length) 
		window.location = link.attr("href");
}); 

$('#main .clickable').hover(function () {
		var link = $(this).find("a:first");
		if (link.attr("href").length) {
			$(this).attr("title",link.attr("title"));
			$(this).addClass("hover");
		}
    }, function() { 
	    $(this).removeClass("hover");
    }); 


//table stripes
$("#main div.content tr:odd").addClass("odd");

//cases
$('ul#cases li').click(function () {
    $('#case-intro').css("display", "none");
    $('#case-quote').css("display", "none");

    $('#case-intro').html($(this).find('div.case-intro').html());
    $('#case-quote').html($(this).find('div.case-quote').html());

    $('ul#cases li').removeClass('selected');

    $('#case-intro').fadeIn("slow");
    $('#case-quote').fadeIn("slow");

    $(this).addClass('selected');
    return false;
});

//clients
$('img#layer-close,#client-layer').click(function () {
	$('#client-layer').css("display", "none");
    return false;
});

$('#clients ul li').click(function () {
    $('#client-layer div.client-layer-content').html($(this).find('div.client-layer-content').html());
    $('#client-layer').fadeIn();
    return false;
});

$('div.clients-content ul').easyListSplitter({ 
		colNumber: 4,
		direction: 'vertical'
});

//ublogsy
if (!$("#blog-column").find("div").length)
	$('#blog-column').hide();

$('#uBlogsy_post_archive .uBlogsy_year_name').click(function () {
	 // toggle months
	 $(this).siblings(".uBlogsy_months").toggle();
	 //$(this).siblings(".uBlogsy_months").find('.uBlogsy_post-items').trigger('click');

	 return false;
 });

 $('#uBlogsy_post_archive .uBlogsy_month_name').click(function () {
	 // toggle months
	 $(this).siblings(".uBlogsy_post-items").toggle();
	 return false;
 });


 // expand current post item's month
 var postItem = $('#uBlogsy_post_archive').find('a[href$="' + window.location.pathname + '"]');
 if (postItem.length == 1) {
 	 $(postItem).parents('#uBlogsy_post_archive .uBlogsy_post-items').show();
	 $(postItem).parents('#uBlogsy_post_archive .uBlogsy_months').show();
 }
 else {
 	 // expand latest month
	 $(postItem).parents('#uBlogsy_post_archive .uBlogsy_months:eq(0)').show();
	 $(postItem).parents('#uBlogsy_post_archive .uBlogsy_months:eq(0) .uBlogsy_post-items:eq(0)').show();

	 // trigger click to show first month
	 //$('.uBlogsy_month_name:eq(0)').trigger('click');
 }
$(".uBlogsy_month").each(function(index) {
    $(this).find("a.uBlogsy_month_name span").append(" (" + $(this).find("li").length + ")");
});
