jQuery(document).ready(function(){
	
	console.log('ready called');
	
	jQuery("a[rel^='prettyPhoto']").prettyPhoto({changepicturecallback: onPictureChanged});
	jQuery("a[rel^='valvePrettyPhoto']").prettyPhoto({changepicturecallback: onPictureChanged});
	
	
	function onPictureChanged() {
		
		console.log('changed');

		var href= 'http://pinterest.com/pin/create/button/?url="'+ encodeURIComponent(location.href.replace(location.hash,"")) +'"&media="' +jQuery('#fullResImage').attr('src');
		jQuery('.pp_social').prepend('<a class="pinterest" href="//www.pinterest.com/pin/create/button/?url='+ encodeURIComponent(location.href.replace(location.hash,"")) +'&media=' + jQuery('#fullResImage').attr('src')+ '&description=' + jQuery('.pp_description').text()+ '" data-pin-do="buttonPin" data-pin-config="above" data-pin-height="28"><img src="//assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png" /></a> ');

	}
	
	//gallery click 
	jQuery("a.wp_pinterest_to_wp_itm_gallery_pop").click(function(){
		  jQuery.prettyPhoto.open(wp_pinterest_to_wp_pins[ jQuery(this).attr('id') ][3],null,wp_pinterest_to_wp_pins[ jQuery(this).attr('id') ][2]);
		 return false;
	});

	 
	//pin click 
	jQuery("a.wp_pinterest_to_wp_itm_pop").click(function(){
		
		jQuery.prettyPhoto.open(jQuery(this).attr('link'),null,jQuery(this).parent().find('.wp_pinterest_to_wordpress_itm_desc').html() + jQuery(this).parent().find('.wp_pinterest_to_wp_itm_lnk').html() );
		 return false;
	});
	
	 
	
});