(function($){
	$.prettyPhoto={version:'3.1.2'};
	$.fn.prettyPhoto=function(pp_settings){
		pp_settings=jQuery.extend({
			//animation_speed:'fast',
			//slideshow:5000,
			//autoplay_slideshow:false,
			//opacity:0.00,
			//show_title:true,
			//allow_resize:false,
			//default_width:500,
			//default_height:344,
			//counter_separator_label:'/',
			//theme:'',
			//horizontal_padding:20,
			//hideflash:false,
			//wmode:'opaque',
			//autoplay:true,
			//modal:false,
			//deeplinking:false,
			//overlay_gallery:false,
			//keyboard_shortcuts:false,
			changepicturecallback:function(){},
			//callback:function(){},
			ie6_fallback:true,
			/*markup:'<div class="pp_pic_holder"><div class="ppt">&nbsp;</div><div class="pp_top"><div class="pp_left"></div><div class="pp_middle"></div><div class="pp_right"></div></div><div class="pp_content_container"><div class="pp_left"><div class="pp_right"><div class="pp_content"><div class="pp_loaderIcon"></div><div class="pp_fade"><a href="#" class="pp_expand" title="Expand the image">Expand</a><div class="pp_hoverContainer"><a class="pp_next" href="#">next</a><a class="pp_previous" href="#">previous</a></div><div id="pp_full_res"></div><div class="pp_details"><div class="pp_nav"><a href="#" class="pp_arrow_previous">Previous</a><p class="currentTextHolder">0/0</p><a href="#" class="pp_arrow_next">Next</a></div><p class="pp_description"></p>{pp_social}<a class="pp_close" href="#">Close</a></div></div></div></div></div></div><div class="pp_bottom"><div class="pp_left"></div><div class="pp_middle"></div><div class="pp_right"></div></div></div><div class="pp_overlay"></div>',gallery_markup:'<div class="pp_gallery"><a href="#" class="pp_arrow_previous">Previous</a><div><ul>{gallery}</ul></div><a href="#" class="pp_arrow_next">Next</a></div>',image_markup:'<img id="fullResImage" src="{path}" />',flash_markup:'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="{width}" height="{height}"><param name="wmode" value="{wmode}" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="{path}" /><embed src="{path}" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="{width}" height="{height}" wmode="{wmode}"></embed></object>',quicktime_markup:'<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="{height}" width="{width}"><param name="src" value="{path}"><param name="autoplay" value="{autoplay}"><param name="type" value="video/quicktime"><embed src="{path}" height="{height}" width="{width}" autoplay="{autoplay}" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/"></embed></object>',iframe_markup:'<iframe src ="{path}" width="{width}" height="{height}" frameborder="no"></iframe>',inline_markup:'<div class="pp_inline">{content}</div>',custom_markup:'',social_tools:'<div class="pp_social"><div class="twitter"><a href="http://twitter.com/share" class="twitter-share-button" data-count="none">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div class="facebook"><iframe src="http://www.facebook.com/plugins/like.php?locale=en_US&href='+location.href+'&amp;layout=button_count&amp;show_faces=true&amp;width=500&amp;action=like&amp;font&amp;colorscheme=light&amp;height=23" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:23px;" allowTransparency="true"></iframe></div></div>'*/
			},
			pp_settings);
			var matchedObjects=this,percentBased=false,
			pp_dimensions,
			pp_open,
			pp_contentHeight,
			pp_contentWidth,
			pp_containerHeight,
			pp_containerWidth,
			windowHeight=$(window).height(),
			windowWidth=$(window).width(),
			pp_slideshow;
			doresize=false,
			scroll_pos=_get_scroll();
			$(window).unbind('resize.prettyphoto').bind('resize.prettyphoto',
			function(){
				_center_overlay();
				_resize_overlay();
			});
			/*if(pp_settings.keyboard_shortcuts){
				$(document).unbind('keydown.prettyphoto').bind('keydown.prettyphoto',
				function(e){
				})
		;};*/


$.prettyPhoto.initialize=function(){
	//settings=pp_settings;
	
	if(settings.theme=='pp_default')settings.horizontal_padding=16;
	if(settings.ie6_fallback&&$.browser.msie&&parseInt($.browser.version)==6)settings.theme="light_square";
	
	//if(settings.theme=='')settings.horizontal_padding=16;
	//if(settings.ie6_fallback&&$.browser.msie&&parseInt($.browser.version)==6)settings.theme="";
	
	theRel=$(this).attr('rel');
	galleryRegExp=/\[(?:.*)\]/;
	isSet=(galleryRegExp.exec(theRel))?true:false;
	//isSet= false;
	pp_images=(isSet)?jQuery.map(matchedObjects,function(n,i){
		if($(n).attr('rel').indexOf(theRel)!=-1)return $(n).attr('href');}):$.makeArray($(this).attr('href'));
	pp_titles=(isSet)?jQuery.map(matchedObjects,function(n,i){
		if($(n).attr('rel').indexOf(theRel)!=-1)return($(n).find('img').attr('alt'))?$(n).find('img').attr('alt'):"";}):$.makeArray($(this).find('img').attr('alt'));
	pp_descriptions=(isSet)?jQuery.map(matchedObjects,function(n,i){
		if($(n).attr('rel').indexOf(theRel)!=-1)return($(n).attr('title'))?$(n).attr('title'):"";}):$.makeArray($(this).attr('title'));set_position=jQuery.inArray($(this).attr('href'),pp_images);
	rel_index=(isSet)?set_position:$("a[rel^='"+theRel+"']").index($(this));
	//_build_overlay(this);
	if(settings.allow_resize)
	$(window).bind('scroll.prettyphoto',function(){_center_overlay();});/*$.prettyPhoto.open();*/return false;}

/*$.prettyPhoto.changePage=function(direction){
	currentGalleryPage=0;
	if(direction=='previous'){
		set_position--;if(set_position<0)set_position=$(pp_images).size()-1;
	}else if(direction=='next'){
		set_position++;
		if(set_position>$(pp_images).size()-1)set_position=0;}else{set_position=direction;};
		rel_index=set_position;
		//if(!doresize)doresize=true;
		//$('.pp_contract').removeClass('pp_contract').addClass('pp_expand');
		//_hideContent(function(){$.prettyPhoto.open();});
};*/

$.prettyPhoto.changeGalleryPage=function(direction){
	if(direction=='next'){
		currentGalleryPage++;
		if(currentGalleryPage>totalPage)currentGalleryPage=0;
		
		}else if(direction=='previous'){
			currentGalleryPage--;
			if(currentGalleryPage<0)currentGalleryPage=totalPage;
			}else{currentGalleryPage=direction;};
			slide_speed=(direction=='next'||direction=='previous')?settings.animation_speed:0;
			slide_to=currentGalleryPage*(itemsPerPage*itemWidth);
			$pp_gallery.find('ul').animate({left:-slide_to},slide_speed);
};

function _checkPosition(setCount){(setCount>1)?$('.pp_nav').show():$('.pp_nav').hide();};

function _center_overlay(){if(doresize&&typeof $pp_pic_holder!='undefined'){scroll_pos=_get_scroll();contentHeight=$pp_pic_holder.height(),contentwidth=$pp_pic_holder.width();projectedTop=(windowHeight/2)+scroll_pos['scrollTop']-(contentHeight/2);if(projectedTop<0)projectedTop=0;if(contentHeight>windowHeight)
return;$pp_pic_holder.css({'top':projectedTop,'left':(windowWidth/2)+scroll_pos['scrollLeft']-(contentwidth/2)});};};


function _get_scroll(){
	//if(self.pageYOffset){
		//return{scrollTop:self.pageYOffset,scrollLeft:self.pageXOffset};
	//}else if(document.documentElement&&document.documentElement.scrollTop){
		//return{scrollTop:document.documentElement.scrollTop,scrollLeft:document.documentElement.scrollLeft};
	//}else if(document.body){
		return{scrollTop:document.body.scrollTop,scrollLeft:document.body.scrollLeft};
	//};
};


function _resize_overlay(){
	//windowHeight=$(window).height(),windowWidth=$(window).width();
	//if(typeof $pp_overlay!="undefined")$pp_overlay.height($(document).height()).width(windowWidth);
};


function _insert_gallery(){
	//if(isSet&&settings.overlay_gallery&&_getFileType(pp_images[set_position])=="image"&&(settings.ie6_fallback&&!($.browser.msie&&parseInt($.browser.version)==6))){
		itemWidth=52+5;
		navWidth=(settings.theme=="facebook"||settings.theme=="pp_default")?50:30;
		itemsPerPage=Math.floor((pp_dimensions['containerWidth']-100-navWidth)/itemWidth);
		itemsPerPage=(itemsPerPage<pp_images.length)?itemsPerPage:pp_images.length;totalPage=Math.ceil(pp_images.length/itemsPerPage)-1;
		if(totalPage==0){
			navWidth=0;
			$pp_gallery.find('.pp_arrow_next,.pp_arrow_previous').hide();
		}else{
			$pp_gallery.find('.pp_arrow_next,.pp_arrow_previous').show();
		};
		galleryWidth=itemsPerPage*itemWidth;
		fullGalleryWidth=pp_images.length*itemWidth;
		
		$pp_gallery.css('margin-left',-((galleryWidth/2)+(navWidth/2))).find('div:first').width(galleryWidth+5).find('ul').width(fullGalleryWidth).find('li.selected').removeClass('selected');
		//goToPage=(Math.floor(set_position/itemsPerPage)<totalPage)?Math.floor(set_position/itemsPerPage):totalPage;
		//$.prettyPhoto.changeGalleryPage(goToPage);
		$pp_gallery_li.filter(':eq('+set_position+')').addClass('selected');
	//}else{
		//$pp_pic_holder.find('.pp_content').unbind('mouseenter mouseleave');
	//}
}


if(!pp_alreadyInitialized&&getHashtag()){

	pp_alreadyInitialized=false;
	hashIndex=getHashtag();
	hashRel=hashIndex;
	hashIndex=hashIndex.substring(hashIndex.indexOf('/')+1,hashIndex.length-1);
	hashRel=hashRel.substring(0,hashRel.indexOf('/'));
	setTimeout(function(){$("a[rel^='"+hashRel+"']:eq("+hashIndex+")").trigger('click');},50);}
	return this.unbind('click.prettyphoto').bind('click.prettyphoto',$.prettyPhoto.initialize);

};

function getHashtag(){
	url=location.href;
	hashtag=(url.indexOf('#!')!=-1)?decodeURI(url.substring(url.indexOf('#!')+2,url.length)):false;
	return hashtag;
};

function setHashtag(){
	if(typeof theRel=='undefined')return;/*location.hash='!'+theRel+'/'+rel_index+'/';*/
};

function getParam(name,url){
	name=name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS="[\\?&]"+name+"=([^&#]*)";
	var regex=new RegExp(regexS);
	var results=regex.exec(url);
	return(results==null)?"":results[1];
}

})(jQuery);

var pp_alreadyInitialized=false;
