$(function(){
	
	$("a[href^='https://app7.vocus']").each(function(){
		store = $(this).attr('href');
		$(this).attr('href', '/vocus/frame?framesrc=' + $.URLEncode(store));
	})

	// initialize scrollable
	$("#footer .scrollable").scrollable({
		'size':1,
		'loop':true,
		'speed':400,
		'circular':true,
		'next':'.scrollable-next',	// Prevents an interaction from the banners
		'prev':'.scrollable-prev'	// Prevents an interaction from the banners
	}).autoscroll({'interval':10000});

	$("#banners .scrollable-banner").scrollable({
		'size':1,
		'loop':true,
		'speed':400,
		'circular':true,
		'next':'.scrollable-next',	// Prevents an interaction from the banners
		'prev':'.scrollable-prev'	// Prevents an interaction from the banners
	}).autoscroll({'interval':6000});

	$("#banners .scrollable-banner").hover(function(){
		$("#banners .scrollable-banner a.right").css({'display':'inline'});
		$("#banners .scrollable-banner a.left").css({'display':'inline'});
	});

	$("#banners .scrollable-banner").mouseleave(function(){
		$("#banners .scrollable-banner a.right").css({'display':'none'});
		$("#banners .scrollable-banner a.left").css({'display':'none'});
	});

	$('.scroller').SetScroller({'velocity':65,'movetype':'linear'});

// begin tabbox transform table to ul/div code orig. from tabbox.tpl

var tabbox_t = new Array();
var tabbox_c = new Array();

$(".tabs_content table:first-child tbody:first-child tr:first-child th").each(function(intIndex){
	tabbox_t[intIndex] = $(this).find('p').html();
})

$(".tabs_content table:first-child td.tabbox").each(function(intIndex){
	tabbox_c[intIndex] = $(this).html();
})
var out = "<ul class='tabs'>";

for (i=0;i<tabbox_t.length;i++) {
	out+="<li><a href='#'>"+tabbox_t[i]+"</a></li>"
}

out+="</ul>";

for (i=0;i<tabbox_c.length;i++) {
	out+="<div class='tc_module'>"+tabbox_c[i]+"</div>"
}

$(".tabs_content").html(out);

// end tabbox code


	
$('a[href="/submitjoblisting"]').each(function(){
	$(this).attr('href', '#')
	$(this).click(function(){
		subform = $("#promote_listing_global");
		subform.find("input[name='ContentNodeID']").setValue($(this).attr('title'));
		subform.find("input[name='NodeID']").setValue($(this).attr('title'));
		subform[0].submit();
	})
})
		
// main menu
//	$('#nav li:hover .popup_list').css({display: 'none'})
	$('#nav > li')
		.mouseenter(function(){
			$(this).children('.popup_list').stop(true, true).css('display','block');
			$(this).addClass('over');
		})
		.mouseleave(function(){
			$(this).children('.popup_list').stop(true, true).css('display','none');
			$(this).removeClass('over');
		})

// tabs switching
if($('.tabs').length > 0) {
	tabMaxHeight = 0;
	$('.tc_module').each(function(){
		if(tabMaxHeight < $(this).height()) {
			tabMaxHeight = $(this).height();
		}
			$(this).css({position: 'static', display: 'none'}).filter('.on').css({display: 'block'})
	});
	tabMaxHeight += 100;
//	$('.tabs_container').css({height: tabMaxHeight+'px'})
	$('.tabs a').click(function(){
		$('.tabs li').removeClass();
		$(this).parent().addClass('on')
		ind = $('.tabs a').index($(this));
		$('.tabs_content .tc_module').slideUp();
		$('.tabs_content .tc_module:eq('+ind+')').slideDown();
		return false;
	});
}


//home tabs 
var home_t_r = new Array('top_stories', 't_national', 't_alabama', 't_florida')
var i = 0;
$(".current_node_id_2 .tabs li").each(function(){
	$(this).attr('id', home_t_r[i]);
	if (i == 0) $(this).find("a").click();
	i++;
})

$('.tabs li a').eq(0).click();

//alert corners

$(".jq_system_message").corner();


var infoboxButton = function(buttonLink, newWindow){
      if(newWindow){window.open(buttonLink);}
	else {document.location.href = buttonLink;}
}

});

$.extend({URLEncode:function(c){var o='';var x=0;c=c.toString();var r=/(^[a-zA-Z0-9_.]*)/;
  while(x<c.length){var m=r.exec(c.substr(x));
    if(m!=null && m.length>1 && m[1]!=''){o+=m[1];x+=m[1].length;
    }else{if(c[x]==' ')o+='+';else{var d=c.charCodeAt(x);var h=d.toString(16);
    o+='%'+(h.length<2?'0':'')+h.toUpperCase();}x++;}}return o;},
URLDecode:function(s){var o=s;var binVal,t;var r=/(%[^%]{2})/;
  while((m=r.exec(o))!=null && m.length>1 && m[1]!=''){b=parseInt(m[1].substr(1),16);
  t=String.fromCharCode(b);o=o.replace(m[1],t);}return o;}
});
