var $j = jQuery.noConflict();

$j(document).ready(function() 
{	
	adjustFooter();
	setSubMenu();
	
	$j('a.lnk_fb').click(function(){
		var newsid = $j(this).parents('.Item').attr('id');
		var newstitle = $j(this).parents().find('h3').html();
		
		if (window.location.hash)
		{
			var newslnk = location.href;
			newslnk = newslnk.replace(window.location.hash,'');
			newslnk = newslnk + '#' + newsid;
		}
		else
		{
			var newslnk = location.href + '#' + newsid;
		}
		
		newslnk = encodeURIComponent(newslnk);
		window.open('http://www.facebook.com/sharer.php?u='+ newslnk +'&t='+encodeURIComponent(newstitle),'sharer','toolbar=0,status=0,width=626,height=436');
	});
	
	$j('a.lnk_url').click(function(){
		var newsid = $j(this).parents('.Item').attr('id');
		
		if (window.location.hash)
		{
			var newslnk = location.href;
			newslnk = newslnk.replace(window.location.hash,'');
			newslnk = newslnk + '#' + newsid;
		}
		else
		{
			var newslnk = location.href + '#' + newsid;
		}
		
		
		if ($j(this).parent().find('.newsUrlBox').size() > 0)
		{
			if ($j(this).parent().find('.newsUrlBox').css('opacity')=='0')
			{
				$j(this).parent().find('.newsUrlBox').animate({'opacity':1},500);
			}			
			else
			{
				$j(this).parent().find('.newsUrlBox').animate({'opacity':0},500);
			}
		}
		else
		{
			$j(this).parent().append('<div class="newsUrlBox">' + newslnk + '</div>');
			$j(this).parent().find('.newsUrlBox').css('opacity',0).animate({'opacity':1},500);
		}
		
		
		
	});
	
	$j('a.ShowNewsComplete').click(function(){
		var thisText = $j(this).parents().find('.NewsComplete');
		//alert($j(thisText).attr('id'));
		
		$j('a.ShowNewsComplete').html('aufklappen');
		if ($j(thisText).html() != '')
		{
			if ($j(thisText).css('display') == 'block')
			{
				$j(thisText).slideUp();
				$j(this).html('aufklappen');
			}
			else
			{
				$j('.NewsComplete').slideUp();
				$j(thisText).slideDown();
				$j(this).html('zuklappen');
			}
		}
	});
	
	$j('.list .Text h3').click(function(){
		$j('a.ShowNewsComplete').html('aufklappen');
		var thisText = $j(this).parents().find('.NewsComplete');
		var buttontext = $j(this).parents().find('.ShowNewsComplete');
		if ($j(thisText).html() != '')
		{
			if ($j(thisText).css('display') == 'block')
			{
				$j(thisText).slideUp();
				$j(buttontext).html('aufklappen');
			}
			else
			{
				$j('.NewsComplete').slideUp();
				$j(thisText).slideDown();
				$j(buttontext).html('zuklappen');
			}
		}
	});
	
	$j('.list .Text h3').hover(function(){
			var thisText = $j(this).parent().children('.NewsComplete');
			if ($j(thisText).html() == '')
			{
				$j(this).css('cursor','auto');
			}
	});

	$j('.contentRight input[type=text]').focus(function() {
		//var initial = $j(this).attr('value');
		$j(this).attr('value','');
	});	
	
	$j('#contactform input[type=text]').focus(function() {
		//var initial = $j(this).attr('value');
		$j(this).attr('value','');
	});	

	/* MENU WIDTH */

	function setSubMenu()
	{
		//append pipe to submenu [FK]
		$j('#menu li ul li').after('<li style="width:5px;border:0px;text-align:center;font-family:Georgia,serif;line-height:18px;">|</li>');
		//and delete the last one
		$j('#menu li ul li:last-child').remove();
	
		var width = 0;
		$j('.csCMSListMenuHighlightedLI ul li').each(function(){
			width += $j(this).outerWidth(true) +20;									 
		});

		$j('.csCMSListMenuHighlightedLI ul').css('width', width);	
		$j('.csCMSListMenuHighlightedLI ul').addClass('clearfix');
	}
	
	
	
	/* END MENU WIDTH */
	
	// validate callback form
	/*
	$j('#plc_lt_zoneSite_pageplaceholder_pageplaceholder_lt_zoneContentRight_CallbackForm_viewBiz_ctl00_btnOK').click(function(){
		
		var valname = $j('#plc_lt_zoneSite_pageplaceholder_pageplaceholder_lt_zoneContentRight_CallbackForm_viewBiz_ctl00_callbackname').attr('value');
		var valnr = $j('#plc_lt_zoneSite_pageplaceholder_pageplaceholder_lt_zoneContentRight_CallbackForm_viewBiz_ctl00_callbacknumber').attr('value');
		
		if ( (valname == 'Mein Name') || (valname == '') )
		{
			$j('#plc_lt_zoneSite_pageplaceholder_pageplaceholder_lt_zoneContentRight_CallbackForm_viewBiz_ctl00_callbackname').css('background-color','#ffd3d3');
			return false;	
		}
		else
		{
			if ( (valnr == 'Meine Telefonnummer') || (valnr == '') )
			{
				$j('#plc_lt_zoneSite_pageplaceholder_pageplaceholder_lt_zoneContentRight_CallbackForm_viewBiz_ctl00_callbacknumber').css('background-color','#ffd3d3');
				return false;
			}
			else
			{
				return true;
			}
		}
	});
	*/
	
	
	// validate newsletter form [FK]
	$j('#plc_lt_zoneSite_pageplaceholder_pageplaceholder_lt_zoneContentRight_NewsletterSubscription_btnSubmit').click(function(){
		
		var valname = $j('#plc_lt_zoneSite_pageplaceholder_pageplaceholder_lt_zoneContentRight_NewsletterSubscription_txtFirstName').attr('value');
		var valemail = $j('#plc_lt_zoneSite_pageplaceholder_pageplaceholder_lt_zoneContentRight_NewsletterSubscription_txtEmail').attr('value');
		
		if ( (valname == 'Mein Name') || (valname == '') )
		{
			$j('#plc_lt_zoneSite_pageplaceholder_pageplaceholder_lt_zoneContentRight_NewsletterSubscription_txtFirstName').css('background-color','#ffd3d3');
			return false;	
		}
		else
		{
			if ( (valemail == 'Meine E-Mail-Adresse') || (valemail == '') )
			{
				$j('#plc_lt_zoneSite_pageplaceholder_pageplaceholder_lt_zoneContentRight_NewsletterSubscription_txtEmail').css('background-color','#ffd3d3');
				return false;
			}
			else
			{
				return true;
			}
		}
	});
	
	//validate contact form
	$j('#plc_lt_zoneSite_pageplaceholder_pageplaceholder_lt_zoneContentLeft_Kontaktformular_viewBiz_ctl00_btnOK').click(function(){
		
		var valname = $j('#plc_lt_zoneSite_pageplaceholder_pageplaceholder_lt_zoneContentLeft_Kontaktformular_viewBiz_ctl00_cName').attr('value');
		var valemail = $j('#plc_lt_zoneSite_pageplaceholder_pageplaceholder_lt_zoneContentLeft_Kontaktformular_viewBiz_ctl00_cMail').attr('value');
		var valmsg = $j('#plc_lt_zoneSite_pageplaceholder_pageplaceholder_lt_zoneContentLeft_Kontaktformular_viewBiz_ctl00_cMessage').attr('value');
		
		
		if ( (valname == 'Name') || (valname == '') )
		{
			$j('#plc_lt_zoneSite_pageplaceholder_pageplaceholder_lt_zoneContentLeft_Kontaktformular_viewBiz_ctl00_cName').css('background-color','#ffd3d3');
			return false;	
		}
		else
		{
			if ( (valemail == 'E-Mail-Adresse') || (valemail == '') )
			{
				$j('#plc_lt_zoneSite_pageplaceholder_pageplaceholder_lt_zoneContentLeft_Kontaktformular_viewBiz_ctl00_cMail').css('background-color','#ffd3d3');
				return false;
			}
			else
			{
				if ( (valmsg == 'Ihre Nachricht') || (valmsg == '') )
				{
					$j('#plc_lt_zoneSite_pageplaceholder_pageplaceholder_lt_zoneContentLeft_Kontaktformular_viewBiz_ctl00_cMessage').css('background-color','#ffd3d3');
					return false;
				}
				else
				{
					return true;
				}
			}
		}
	});
	
	
	
});

/*
	$j('#callback submit').click(function() {
  		alert('Handler for .submit() called.');
		return false;
	});
*/


function adjustFooter()
{
	var footerheight = $j('#footer').height();
	
	$j('ul.CMSSiteMapList').addClass('clearfix');
	var sitemapheight = $j('#sitemap').outerHeight();
	var fheight = sitemapheight + 30;
	
	$j('#FooterWrap').css('height',fheight);
	$j('#footerContent').css('height',fheight);
	$j('#site').css('padding-bottom',fheight);
	$j('#footer').css({ 
		'margin-top' : (fheight*-1),
		'height' : fheight
	});
	
	//alert(sitemapheight);
}

var SeitenURL = 	document.location.href;
var SeitenTitel = 	document.title;
var Kommentar = 	'Steuerberater Carsten Schupp';


function setBookmark()
{
	if (window.sidebar)
    {
		window.sidebar.addPanel(SeitenTitel,SeitenURL,Kommentar);
    }
	else if (window.opera && window.print)
    {
		var elem = document.createElement('a');
		elem.setAttribute('href',SeitenURL);
		elem.setAttribute('title',SeitenTitel);
		elem.setAttribute('rel','sidebar');
		elem.click();
	}
	else if (document.all)
    {
		window.external.AddFavorite(SeitenURL,SeitenTitel);
    }
}

function recommend()
{	
	$j('#lboverlay #dialog').css('width','400px');
	$j('#lboverlay #dialog').css('margin','80px auto 0 -200px');
	$j('#TargetFrame').attr('src', 'http://www.steuerberater-schupp.de/Seite-empfehlen.aspx');
	window.scrollTo(0, 0);
	
	var body = $j(body);
	$j("#lboverlay").css("height", body.height());
	$j("#lboverlay").css("visibility", "visible");
	
	$j(document).keyup(function(event)
	{
		if (event.keyCode == 27) 
		{
			$j("#lboverlay").css("visibility", "hidden");
			$j('#TargetFrame').attr('src', '');
		}
	});

}

function closePopup()
{
	$j("#lboverlay").css("visibility", "hidden");
}

function facebook()
{
	var likepage = 'http://www.facebook.com/sharer.php?u=' + SeitenURL + '&t=' + SeitenTitel;
	window.open(likepage);	
}


function newsletterOpen(url)
{	
	$j('#lboverlay #dialog').css('width','600px');
	$j('#lboverlay #dialog').css('margin','80px auto 0 -300px');
	$j('#TargetFrame').attr('src',url);
	window.scrollTo(0, 0);
	
	var body = $j(body);
	$j("#lboverlay").css("height", body.height());
	$j("#lboverlay").css("visibility", "visible");
	
	$j(document).keyup(function(event)
	{
		if (event.keyCode == 27) 
		{
			$j("#lboverlay").css("visibility", "hidden");
			$j('#TargetFrame').attr('src', '');
		}
	});

}

function checkParent()
{
	//[FK] framebuster - check whether this is a frame or backend
	var thisloc = document.location.href;
	var parloc = parent.location.href;
	
	if (thisloc != parloc)
	{
		if (parloc.indexOf('editpage.aspx') > 0)
		{
		}
		else
		{
			parent.location.href = thisloc;
		}
	}
}

	function removeValue(obj)
	{
		obj.value = '';
	}
	
	function checkValue(obj,str)
	{
		if (obj.value == '')
		{	
			//alert("empty");
			obj.value = str;
		}
		//alert(obj + ' ' + str);
	}
	
	function toggleDept(obj)
	{
		//alert(obj);
		
		if ( $j('#abt_'+obj).css('display') == 'block')
		{
			//alert("visible");
			$j('#togglnk_' + obj).css('background-position','left 4px');
			
		}
		else
		{
			$j('#togglnk_' + obj).css('background-position','left -14px');
		}
		$j('#abt_'+obj).slideToggle();
	}
	
	function initNewsPage()
	{
		if (window.location.hash!='')
		{
			var toOpen = $j(window.location.hash);
			$j(toOpen).find('.Text .NewsComplete').css('display','block');
			$j(toOpen).find('.ShowNewsComplete').html('zuklappen');
		}
	}
