function extendLinks(_targetList,_targetItem) {
	if ( $(_targetList).length > 0 ) {
		$(_targetItem).click(function(evt) {
			evt.preventDefault();
			_el = $(this).find('a');
			
			if ( _el.attr('target') === '_blank' ) {
				window.open(_el.attr('href'), '');						
			} else {
				window.location = _el.attr('href');						
			};						
		});
		
		$(_targetItem).hover(function() {
			$(this).toggleClass('hover');
		});	
		
	};	
};

$(document).ready(function() {
	$("a[rel=gal]").fancybox({
		'padding': '35',
		'overlayOpacity': '0.8',
		'overlayColor': '#1f1f1f',
		'titlePosition': 'inside',
		'titleFormat': function (title, currentArray, currentIndex, currentOpts) {
			return '<span class="fancyTitle">' + (currentIndex + 1) + ' / ' + currentArray.length + '</span>';
		}
	});

	if ( ( $('html').hasClass('iphone') == false || $('html').hasClass('ipad') == false ) ) { 
		flashembed('autotorq_hype_container',"/js/autotorq4.swf"); 		
	};
	
	$('.prefNav li:first-child').addClass('first-child');
	$('.prefNav li:last-child').addClass('last-child');

	if ( $('#gfc').length > 0 ) {
		// We only want these styles applied when javascript is enabled	
		$('#gfc div.navigation').css({'width' : '135px', 'float' : 'right'});
		$('#gfc div.gContent').css('display', 'block');


		// Initially set opacity on thumbs and add
		// additional styling for hover effect on thumbs	
		var onMouseOutOpacity = 0.67;
		$('#gfc #thumbs ul.thumbs li').opacityrollover({
			mouseOutOpacity:   onMouseOutOpacity,
			mouseOverOpacity:  1.0,
			fadeSpeed:         'fast',
			exemptionSelector: '.selected'
		});
		
		// Initialize Advanced Galleriffic Gallery	
		var gallery = $('#gfc #thumbs').galleriffic({
			delay:                     2500,
			numThumbs:                 3,
			preloadAhead:              10,
			enableTopPager:            false,
			enableBottomPager:         false,
			maxPagesToShow:            7,
			imageContainerSel:         '#slideshow',
			controlsContainerSel:      '#controls',
			captionContainerSel:       '#caption',
			loadingContainerSel:       '#loading',
			renderSSControls:          false,
			renderNavControls:         false,
			playLinkText:              'Play Slideshow',
			pauseLinkText:             'Pause Slideshow',
			prevLinkText:              '&lsaquo; Previous Photo',
			nextLinkText:              'Next Photo &rsaquo;',
			nextPageLinkText:          'Next &rsaquo;',
			prevPageLinkText:          '&lsaquo; Prev',
			enableHistory:             false,
			autoStart:                 false,
			syncTransitions:           true,
			defaultTransitionDuration: 900,
			onSlideChange:             function(prevIndex, nextIndex) {
				// 'this' refers to the gallery, which is an extension of $('#thumbs')
				this.find('ul.thumbs').children()
					.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
					.eq(nextIndex).fadeTo('fast', 1.0);
			},
			onPageTransitionOut:       function(callback) {
				this.fadeTo('fast', 0.0, callback);
			},
			onPageTransitionIn:        function() {
				this.fadeTo('fast', 1.0);
			}
		});		
	};
	
	extendLinks('.colR .posts','.colR .posts li');
	extendLinks('.blogR .bloggers','.blogR .bloggers li');
	
	//alert($('html').attr('class'));
});


function ChangeLocation(name) {
    if (name !== '') {
        var currentUrl = $.url(location.href);
        var blogUrl = "blog";
        var builtUrl = "/" + blogUrl + "?blogger=" + name;

        location.href = builtUrl;
    }
}

