function elementVisibility(id, visible){
	if (visible)
		$("#"+id).show();
	else
		$("#"+id).hide();
}
function showProject(title)
{
	accordion.accordion('activate' , 1);
	var e = $("#work_list li a[title='"+title+"']");
	if (e.length != 0)
	{
		setTimeout(function(){
			e.click();
		},500);
	}

}
function companyClick(evt, url, target)
{

	$(".company .active").removeClass('active');
	$(evt.$target).addClass('active');
	ajaxLoadData(url,target, function()
			{
				if ($(".company .scroll-pane").length > 0)
					$('.company .scroll-pane').jScrollPane({showArrows: true});
			});

}
function ajaxLoadData(url, target, callback){
if (url == "_workShowVideo.php?data=Choose a Video:" && target == 'work_video')
	return false;
$.ajax(
		{
			type 	: "GET",
			url 	: url,
			success : function(response)
			{
				$("#"+target).html(response);
				if (callback)
					callback();
			}
		});
}
$(function()
		{
		$('#work_scroll').jScrollPane({showArrows: true});

		accordion = $('#content').accordion({
			header: 'h3.toggler',
			autoHeight: false,
			collapsible: true,
			change: function(event,ui)
			{
				if ($(ui.newHeader).hasClass('work'))
					$('#work_scroll').jScrollPane({showArrows: true});
			}});
		var toShow = $(".toggler.news");
		$(".toggler.news").next().show();
		toShow.attr('aria-expanded','true').attr("tabIndex", "0").focus();
		toShow.addClass("ui-accordion-header ui-helper-reset ui-state-active ui-corner-top ui-state-focus");
		$(toShow.next()).addClass("ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom ui-accordion-content-active");
		updateShareData();

		$(".workListItem a.thickbox").each(function()
		{
		   var href = $(this).attr("href").split("/");
		   $(this).attr("href" , "/_workShow.php?id="+href[href.length - 1]+"&amp;width=820&amp;height=590")
		   $(this).click(function()
		   {
		    setTimeout(function()
		    {
			addthis.button("#addthisbutton" , {},updateShareData());
		    },1000);


		   });

		});


  });
function updateShareData()
{
	if ($("#titleUrl").length > 0)
 		addthis_share =
		    {
			url: domain + "" + $("#titleUrl").attr("href"),
			title: "METAphrenie: "+$("#titleUrl").text(),
			content: $("#workshowContent *").html()
		    };
	else
 		addthis_share =
		    {
			url: domain,
			title: "METAphrenie: A Design Company"
		    };
 return addthis_share;
}
/** imageHandler **/
function imageGetSelected(){
	return imageSelected;
}

function imageNext(){
	imageSelected++;
	imageShowCurrent();
	return imageSelected;
}

function imagePrev(){
	imageSelected--;
	imageShowCurrent();
	return imageSelected;
}

function imageReset(){
	imageSelected = 0;
}

function imageShowCurrent(){
	var span = document.getElementsByTagName("span");
	var imagesNum = 1;
	for(var a=0; a<span.length; a++){
		var obj = span[a];
		if(obj.className == "imagesNum")
			imagesNum = obj.firstChild.nodeValue;
	}
	var selected = imageSelected;
	if(selected < 0)
		selected += (imagesNum)*(Math.abs(selected));
	for(var a=0; a<span.length; a++){
		var obj = span[a];
		if(obj.className == "imageSelected")
			obj.firstChild.nodeValue = (selected%imagesNum)+1;
	}
}

imageReset();