
jQuery(document).ready( function($) {
								 
$('.entry img').each(function() {

	if ( $(this).attr('offsetWidth') > 560 ) {
		$maxWidth = 560;
		$imgRatio =   $(this).attr('offsetHeight') / $(this).attr('offsetWidth');
		$newHeight = Math.round($maxWidth * $imgRatio);
		
		$(this).animate({width: 560}, 1);
		$(this).animate({height: $newHeight}, 1);
	}
});


$('.entry_small img').each(function() {

	if ( $(this).attr('offsetWidth') > 270 ) {
		$maxWidth = 270;
		$imgRatio =   $(this).attr('offsetHeight') / $(this).attr('offsetWidth');
		$newHeight = Math.round($maxWidth * $imgRatio);
		
		$(this).animate({width: 270}, 1);
		$(this).animate({height: $newHeight}, 1);
	}
});


		
	if ($('.jTab').css('width') != "1337px"){
		$('.linkicon').css('margin-top', '-55px');
		$('.linkicon').css('padding-bottom', '55px');
									 
		$('.linkicon').hover(
		  function () {
			$(this).stop().animate({marginTop: 0, paddingBottom: 0}, 333);
		  },
		  function () {
			$(this).stop().animate({marginTop: -55, paddingBottom: 55}, 333);
		  }
		);
	}
	
$('.breadcrumbs').hide();
$('.breadcrumbs').fadeIn(1000);


$slidecount = $('#proinslide').attr("clientWidth") / 650 - 3;

for ($ii=0; $ii < $slidecount; $ii++) {
	//$(".smalllink"+$ii).animate({opacity: 0.75}, 1);
	$(".smalllink"+$ii).click(function(ev){
		ev.preventDefault();
		$slide = false;
		$pausewait = 5;
		$.fn.slider();
		//alert($slide + ":" + $pausewait);
		$ii = $(this).attr('className');
		$ii = $ii.split("smalllink");
		$ii = $ii[1];
		$margin = -650 * $ii;
		
		$pos = $('#proinslide').attr('offsetLeft');
		$speed = 1000 + (Math.abs($margin - $pos)/10);

		$('#proinslide').stop(true);
		$('#proinslide').animate({marginLeft: $margin}, $speed);
		//$('.prolittlelink img').animate({opacity: .75}, 1);
		//$(this).find('img:first').animate({opacity: 1}, 1);
		$('.prolittlelink img').css('borderColor','#DDD');
		$(this).find('img:first').css('borderColor','#333');
	});
}

$slide = true;
$pausewait = 1;
$waittime = $('.jTab').css('height').split('px');
$waittime = parseInt($waittime[0]) + 1500;


$.fn.slider = function () {
	if ($slide == true){
		//alert("Slide == true");
		$('#proslider').animate({marginRight: 0}, $waittime, function() { 
				if ($slide == true){
				//alert("Done Waiting");
				$curLeft = $('#proinslide').attr('offsetLeft');
				$nextLeft = $curLeft - 650;
				$maxLeft = ($slidecount) * 650 * -1;
				//alert($curLeft + " " + $maxLeft);
				if ($nextLeft < $maxLeft){
					$('#proinslide').css('margin-left','0px');
					$curLeft = 0;
					$nextLeft = $curLeft - 650;
				}
				$nextSlide = Math.abs($curLeft / 650) + 1;
				if($nextSlide > $slidecount - 1) $nextSlide = 0;
				$('.prolittlelink img').css('borderColor','#DDD');
				$(".smalllink"+$nextSlide).find('img:first').css('borderColor','#333');
				$('#proinslide').stop(true, false);
				//alert($curLeft +":"+$nextLeft);
				$('#proinslide').animate({marginLeft: $nextLeft}, 1500);
				return $.fn.slider();
				}
		});
	
	}else{
		//alert("Slide is showing flase");
		$('#proslider').animate({marginRight: 0}, 1000, function() {
			$pausewait -= 1;
			if($pausewait <= 0){
				$slide = true;	
			}
			return $.fn.slider();
		});
	}
}
$.fn.slider()
	
	
$("menu li").hover(function(){ //Main menu - Drop-Down List functionality

if(($(this).parent().attr('nodeName') != "MENU") && (jQuery.support.opacity)) { //disable for IE - IE shouldn't exist. At all.
$(this).parent().parent().css('background-color', 'black'); //follow-through bg color

$imgURL = $('.hidden-img-url').css('background-image'); // get absolute img loc
// set with-child icon to highlighted
$(this).parent().parent().find('a:first').find('.with-child').css('backgroundImage', $imgURL );

}
//if not the top level of the menu (pre-drop down) and not IE
if(($(this).parent().attr('nodeName') != "MENU") && (jQuery.support.opacity)) {
//HL text
$(this).parent().parent().find('span:first').css('color', '#EEE');
}

if($(this).parent().attr('nodeName') == "MENU") { //(top lvl menu)
//find first drop down ul, make visible, set left position

$(this).find('ul:first').css({visibility: "visible",display: "none"}).stop(true, true).show(200).css({left: $(this).last('li').attr('offsetLeft') + 'px'});
//IF IE6 or 7 or IE8 in IE7 mode
if((!jQuery.support.boxModel) || (document.documentMode && document.documentMode == 7)) {
//account for weird offset in some IE versions
$(this).find('ul:first').css({visibility: "visible",display: "none"}).stop(true, true).show(200).css({left: $(this).last('li').attr('offsetLeft') + 0 + 'px'});
}

}else {

//for all other lvls of menu
$(this).find('ul:first').css({visibility: "visible",display: "none"}).stop(true, true).show(200).css({left: $(this).last('ul').attr('clientWidth') + 'px'});

}

//// grab the width of the widest link in the next ul of the menu
var childCount = 0;
var wideChild = 0;

while (childCount < $(this).find('ul:first').children().length){
$childrenArray = ($(this).find('ul:first').attr('children'));
$childWidth = $($childrenArray[childCount]).find('a:first').attr('clientWidth');

if($childWidth > wideChild){
wideChild = $childWidth;
}

childCount++;
}

//// adjust all links to be as wide as the widest

childCount = 0;
while (childCount < $(this).find('ul:first').children().length){

$childrenArray = ($(this).find('ul:first').attr('children'));
$($childrenArray[childCount]).find('a:first').css('width', wideChild + 'px');

childCount++;
}


},function(){
///// on roll-out - set everything back to normal

$(this).find('ul:first').fadeOut(200);
$(this).parent().parent().css('background-color', '');
$(this).parent().parent().find('span:first').css('color', '');
$(this).parent().parent().find('a:first').find('.with-child').css('backgroundImage', '' );
}
); //END drop-down menu



$('menu li a').attr('title', ''); //Remove Titles - causes problems in some browsers, mouse-over pop-up title closes menu

$('menu li').each( function () { //SET menu ul props on load
											  
if ( $(this).parent().attr('nodeName') == "MENU" ){
	if ($(this).find('ul:first').children().length){
		$temp = $(this).find('a:first').html();
		$(this).find('a:first').html($temp + '<span class="menu-drop"></span>');
	}
}
											  
var childCount = 0;

while (childCount < $(this).find('ul:first').children().length){
$childrenArray = ($(this).find('ul:first').attr('children'));

if( $($childrenArray[childCount]).children().length > 1 ){ //disabled/skipped in IE
$spanhtml = '<span class="spanpad">' + $($childrenArray[childCount]).find('a:first').html() + '<span class="with-child"></span></span>';
$($childrenArray[childCount]).find('a:first').html($spanhtml);
}else {
$spanhtml = '<span class="spanpad">' + $($childrenArray[childCount]).find('a:first').html() + '</span>';
$($childrenArray[childCount]).find('a:first').html($spanhtml);
}

childCount++;
}
}
);




$imgURL = $('.hidden-current-url').css('backgroundImage') + ' bottom repeat';
//alert($imgURL);
$("menu li.current_page_item").find('a:first').css('color', '#FEFEFE');
$("menu li.current_page_parent").find('a:first').css('color', '#FEFEFE');
$("menu li.current_page_ancestor").find('a:first').css('color', '#FEFEFE');
$("menu li.current_page_item").find('a:first').css('background', $imgURL);
$("menu li.current_page_parent").find('a:first').css('background', $imgURL);
$("menu li.current_page_ancestor").find('a:first').css('background', $imgURL);



$("a").click(function(ev){
				$('.breadcrumbs').fadeOut(500);
				$("menu li").find('ul').fadeOut(500);
				return true;
});

$(".totop").click(function(ev){
				$('html, body').animate({scrollTop:0}, 1000);
				ev.preventDefault();
});

$(".gotoTop").click(function(ev){
				$('html, body').animate({scrollTop:0}, 1000);
				ev.preventDefault();
});
								
								
});


function workTheMagic() {
	  $('#navigation ul:first').replaceWith('<menu>' +  $('#navigation ul:first').html() + '</menu>');
}
