jQuery.noConflict();


/**
   * PK Init Vars
*/

	var a47_stage_width = 0;
	var a47_stage_height = 0;
	var a47_new_item = -1;
	var a47_old_item = 0;
	var a47_new_type = "";
	var a47_old_type = "";
	var a47_slide_verse = "next";
	var a47_slide_restart = false;
	var a47_thumbs_open = false;
	var a47_info_open = false;
	var a47_image_width = 0;
	var a47_image_height = 0;
	var a47_is_first = true;
	var a47_is_loader = false;
	var a47_interval = null;
	var a47_deep_link_change_item = false;

	var a47_video_width = a47_gallery_video_width;
	var a47_video_height = a47_gallery_video_height;
	var a47_info_max_height = a47_gallery_info_max_height;
	var a47_thumbs_width = a47_gallery_thumbs_width;
	var a47_thumbs_height = a47_gallery_thumbs_height;
	var a47_thumbs_visible = a47_gallery_thumbs_visible;
	var a47_shadow = a47_gallery_shadow;
	var a47_images_up_scale = a47_gallery_images_up_scale;
	var a47_videos_up_scale = a47_gallery_videos_up_scale;
	var a47_button_info_open_label = a47_gallery_button_info_open_label;
	var a47_button_info_close_label = a47_gallery_button_info_close_label;
	var a47_button_slideshow_on_label = a47_gallery_button_slideshow_on_label;
	var a47_button_slideshow_off_label = a47_gallery_button_slideshow_off_label;
	var a47_is_slideshow = a47_gallery_slideshow_auto_start;
	var a47_interval_timer = a47_gallery_slideshow_interval * 1000;

	var a47_media = [];
	var a47_infos = [];


/*
  * Document / Window Events
*/

	jQuery(document).ready(function() {

		jQuery("body").removeClass("a47_standard_pages");
		jQuery("#wrapper").css("visibility", "hidden").removeClass("a47_center_box").show();

		a47_stage_width = jQuery(window).width();
		a47_stage_height = jQuery(window).height();

		pkInitDeepLink();

		pkCreateMainMenu();
		pkCreateGallery();
		pkCreateControls();
		pkCreateThumbs(a47_thumbs_width, a47_thumbs_height, a47_thumbs_visible);

		jQuery("#wrapper").css("visibility", "visible");

	});

	jQuery(window).resize(function() {

		a47_stage_width = jQuery(window).width();
		a47_stage_height = jQuery(window).height();

		pkResizeMainMenu();
		pkResizeControls();
		pkResizeGallery();
		pkResizeThumbs();
		pkResizeInfo();
		
		pkResizePreloader();

		pkSlideshow();

	});


/**
   * PK Init Deep Link
*/

	function pkInitDeepLink() {

		jQuery.address.externalChange(function(event) {

			a47_deep_link_change_item = true;

			if(event.value == "" || event.value == "/") {
				
				a47_is_first = true;

				jQuery("#a47_thumbs li a").filter(":eq(0)").trigger("click", [true]);

			} else {

				jQuery("#a47_thumbs li a").each(function() {

					if(jQuery(this).attr("data-deepLinking") == event.pathNames[0]) {

						jQuery(this).trigger("click", [true]);

					}
				});

			}

 		});

	}


/**
   * PK Create Main Menu
*/

	function pkCreateMainMenu() {

		var menu = jQuery("nav");
		var logo = jQuery("header h1");

		menu.hide();
		logo.hide();;

		menu.css({ "position" : "absolute", "left" : Math.round((a47_stage_width / 2) - (menu.outerWidth() / 2)) + "px", "top" : 0 + "px"}).show();
		logo.css({ "position" : "absolute", "left" : "0px", "top" : Math.round(a47_stage_height / 8) + "px" }).show();

	}


/**
   * PK Resize Main Menu
*/

	function pkResizeMainMenu() {

		var menu = jQuery("nav");
		var logo = jQuery("header h1");
	
		menu.css({ "left" : Math.round((a47_stage_width / 2) - (menu.outerWidth() / 2)) + "px", "top" : 0 + "px" });
		logo.css({ "position" : "absolute", "left" : "0px", "top" : Math.round(a47_stage_height / 8) + "px" }).show();
		
	}


/**
   * PK Create Gallery
*/

	function pkCreateGallery() {

		var gallery_item = jQuery("#a47_gallery ul:first li");

		gallery_item.each(function(e) {

			a47_media[e] = jQuery("div:first", this).html();
			a47_infos[e] = jQuery(".a47_description", this).html();
			
			jQuery("div:first", this).removeClass("a47_alignnone");

			jQuery("div:first", this).empty();
			jQuery(".a47_description", this).empty().hide();
			jQuery(this).css({ "position" : "absolute", "width" : 0 + "px", "height" : 0 + "px" });
			
			(a47_shadow == true) ? jQuery(this).addClass("a47_shadow") : jQuery(this).css({ "background" : "none" });
			
			jQuery(this).hide();

		});

	}


/**
   * PK Resize Gallery
*/

	function pkResizeGallery() {

		var gallery_items = jQuery("#a47_gallery ul:first li");
		var current_mask = gallery_items.filter(":eq(" + a47_new_item + ")");
		var current_mask_type = current_mask.find("div:first").attr("class");

		var current_image = gallery_items.filter(":eq(" + a47_new_item + ")").find("div:first img");
		var current_video = gallery_items.filter(":eq(" + a47_new_item + ")").find("div:first");
		
		for(var i = 0; i < gallery_items.length; i++) {

			if(i == a47_new_item) {

				if(a47_info_open == false) {

					(a47_new_type == "image") ? pkResizeObject(current_image, current_mask, "image", current_image.width(), current_image.height(), false) : pkResizeObject(current_video, current_mask, "video", a47_video_width, a47_video_height, false);
					
					pkPositionObject(current_mask);

				} else {

					(a47_new_type == "image") ? pkResizeObject(current_image, "", "image", current_image.width(), current_image.height(), false) : pkResizeObject(current_video, "", "video", a47_video_width, a47_video_height, false);
					(a47_new_type == "image") ? current_mask.css({ "width" : 0 + "px", "height" : current_image.height() + "px" }) : current_mask.css({ "width" : 1 + "px", "height" : current_video.height() + "px" });
					
					pkPositionObject(current_mask, true);
				}

			} else {
				
				gallery_items.filter(":eq(" + i + ")").find("div:first").empty();
				gallery_items.filter(":eq(" + i + ")").css({ "width" : 0 + "px", "height" : 0 + "px" });
				gallery_items.filter(":eq(" + i + ")").hide();

			}
		}

	}


/**
   * PK Create Controls
*/

	function pkCreateControls() {

		var footer = jQuery("footer");
		var controls = jQuery("#a47_controls");
		var button_info = jQuery("#a47_button_info");
		var button_slideshow = jQuery("#a47_button_slideshow");
		var gallery_tot_items = jQuery("#a47_gallery ul:first li").length;
		var buttons = jQuery("#a47_button_next, #a47_button_prev, #a47_button_thumbs, #a47_button_info, #a47_button_slideshow");

		if(gallery_tot_items == 1) {
			if(a47_infos[0] == null) {

				controls.css({ "width" : 0 + "px", "padding" : 0 + "px", "border" : "none" });
				button_slideshow.hide();
				button_info.hide();

			} else {

				controls.css({ "width" : 0 + "px", "padding" : 0 + "px", "border-right" : "none" });
				button_slideshow.hide();

			}
		}

		controls.css({ "position" : "absolute", "left" : Math.round((a47_stage_width / 2) - (controls.outerWidth() / 2)) + "px", "top" : 0 + "px" });
		button_info.css({ "position" : "absolute", "left" : Math.round((a47_stage_width / 2) + (controls.outerWidth() / 2)) + "px", "top" : 0 + "px" });
		button_slideshow.css({ "position" : "absolute", "left" : Math.round((a47_stage_width / 2) - (controls.outerWidth() / 2) - 110) + "px", "top" : 0 + "px" });
		footer.css({ "position" : "absolute", "top" : Math.round(a47_stage_height - 30) + "px" });

		buttons.each(function() {
			jQuery(this).removeAttr("href");
			jQuery(this).css({ "cursor" : "pointer" });
			
 			jQuery(this).click(function(e) {
				switch(jQuery(e.currentTarget).attr("id")) {

					case "a47_button_next":

						var item_index = a47_new_item;

						if(item_index + 1 > gallery_tot_items - 1) {

							a47_slide_restart = true;
							item_index = 0;
 
						} else {

							a47_slide_restart = false;
							item_index = item_index + 1;

						}

						a47_slide_verse = "next";
						jQuery("li a", "#a47_thumbs").filter(":eq("+ item_index +")").trigger("click", [true]);

						break;

					case "a47_button_prev":

						var item_index = a47_new_item;

						if(item_index - 1 < 0) {

							a47_slide_restart = true;
							item_index = gallery_tot_items - 1;

						} else {

							a47_slide_restart = false;
							item_index = item_index - 1;

						}

						a47_slide_verse = "prev";
						jQuery("li a", "#a47_thumbs").filter(":eq("+ item_index +")").trigger("click", [true]);

						break;

					case "a47_button_thumbs":

						(a47_thumbs_open == false) ? pkManageThumbs("show") : pkManageThumbs("hide", jQuery("#a47_thumbs").height());

						break;

					case "a47_button_info":

						if(a47_infos[a47_new_item] == null || a47_is_loader == true) {

							return true;

						}

						if(a47_thumbs_open == true) { pkManageThumbs("hide", jQuery("#a47_thumbs").height()); }
						(a47_info_open == false) ? pkShowInfo() : pkHideInfo("info");

						break;

					case "a47_button_slideshow":

						if(a47_is_slideshow == false) {

							a47_is_slideshow = true;
							jQuery(this).text(a47_button_slideshow_on_label);
							jQuery("#a47_button_next").trigger("click", [true]);

						} else {

							a47_is_slideshow = false;
							clearInterval(a47_interval);
							jQuery(this).text(a47_button_slideshow_off_label);
							jQuery("#a47_slideshow_bar").stop().animate({ "width" : 0 + "px" }, 400, "easeOutExpo");

						}

						break;
				}
			});
		});

		button_info.text(a47_button_info_open_label);
		(a47_is_slideshow == false) ? button_slideshow.text(a47_button_slideshow_off_label) : button_slideshow.text(a47_button_slideshow_on_label);
		
		if ((navigator.userAgent.indexOf('iPhone') != -1) ||  (navigator.userAgent.indexOf('iPod') != -1) ||  (navigator.userAgent.indexOf('iPad') != -1)) { 
			
			jQuery("#a47_gallery").touchwipe({
				wipeLeft: function() { jQuery("#a47_button_next").trigger("click", [true]); },
				wipeRight: function() { jQuery("#a47_button_prev").trigger("click", [true]); },
				min_move_x: 20,
				min_move_y: 20,
				preventDefaultEvents: true
			});
			
		}

	}


/**
   * PK Resize Controls
*/

	function pkResizeControls() {

		var footer = jQuery("footer");
		var controls = jQuery("#a47_controls");
		var controls_width = controls.outerWidth();
		var button_info = jQuery("#a47_button_info");
		var button_slideshow = jQuery("#a47_button_slideshow");

		controls.css({ "position" : "absolute", "left" : Math.round((a47_stage_width / 2) - (controls_width / 2)) + "px", "top" : 0 + "px" });
		button_info.css({ "position" : "absolute", "left" : Math.round((a47_stage_width / 2) + (controls_width / 2)) + "px", "top" : 0 + "px" });
		button_slideshow.css({ "position" : "absolute", "left" : Math.round((a47_stage_width / 2) - (controls_width / 2) - 110) + "px", "top" : 0 + "px" });
		footer.css({ "position" : "absolute", "top" : Math.round(a47_stage_height - 30) + "px" });

	}


/**
   * PK Create Thumbs
*/

	function pkCreateThumbs(thumbs_width, thumbs_height, visible) {

		var root = jQuery("#a47_thumbs");
		var gallery_items = jQuery("#a47_gallery ul:first li");
		var thumbs = jQuery("li", root);
		var tot_thumbs = thumbs.length;
		var root_width = (tot_thumbs >= visible) ? (thumbs_width * visible) + (1 * visible) : (thumbs_width * tot_thumbs) + (1 * tot_thumbs);

		jQuery("ul", root).css({"top" : thumbs_height + "px", "width" : Math.round((thumbs_width * tot_thumbs) + (1 * tot_thumbs)) + "px" });

		var ul_width = jQuery("ul", root).width();

		root.css({ "width" : root_width + "px", "height" : thumbs_height + "px", "left" : Math.round((a47_stage_width / 2) - (root_width / 2)) + "px", "top" : Math.round(a47_stage_height - (root.height() + thumbs_height)) + "px" });

		thumbs.each(function(i) {
			jQuery(this).css({ "width" : thumbs_width + "px", "height" : thumbs_height + "px" });

			jQuery('a', this).address(function() {

				if(a47_is_first == false && a47_is_loader == false) {

					return jQuery(this).attr('data-deepLinking');

				}

			});

			jQuery("a", this).click(function(e) {
				if(a47_is_loader == true || i == a47_new_item) {

					return true;

				}

				a47_old_item = a47_new_item;
				a47_new_item = i;

				a47_new_type = gallery_items.filter(":eq(" + a47_new_item + ")").find("div:first").attr("class").split("_")[1];
				if(a47_old_item != -1) { a47_old_type = gallery_items.filter(":eq(" + a47_old_item + ")").find("div:first").attr("class").split("_")[1]; }

				gallery_items.filter(":eq(" + a47_new_item + ")").show();

				if(a47_new_type == "image") {

					var dalay = (jQuery.browser.opera) ? 200 : 0;

					if(a47_slide_restart == false) {
						(a47_new_item > a47_old_item) ? a47_slide_verse = "next" : a47_slide_verse = "prev";
					}

					gallery_items.filter(":eq(" + a47_new_item + ")").find(".a47_image").html(a47_media[a47_new_item]);
					gallery_items.filter(":eq(" + a47_new_item + ")").find(".a47_image img").a47_preloader({
						beforeLoading:function(){ a47_is_loader = true; pkShowPreloader(); },
						afterLoading:function(){ 

							pkPngFix();
							(a47_deep_link_change_item == false) ? pkChangeItem("slide") : pkChangeItem("direct");
							pkHidePreloader();

						},
						delay:dalay,
						speedIn:0
					});
					
				} else {

					if(a47_slide_restart == false) {
						(a47_new_item > a47_old_item) ? a47_slide_verse = "next" : a47_slide_verse = "prev";
					}

					(a47_deep_link_change_item == false) ? pkChangeItem("slide") : pkChangeItem("change");

				}

				(a47_infos[a47_new_item] == null) ? jQuery("#a47_button_info").fadeOut(200) : jQuery("#a47_button_info").fadeIn(200);

				a47_slide_restart = false;
				
				thumbs.removeClass("current");
				jQuery(this).parent().addClass("current");

				pkUpDateCounter(a47_new_item, gallery_items.length);
			});

		});

		root.mousemove(function(e){
			if(ul_width > root_width) {

				var distance = e.pageX - root.offset().left;
				var percentage = distance / root_width;
				var targetX = 10 - Math.round(((ul_width + 20) - root_width) * percentage);
				jQuery("ul", root).animate({left : [targetX + "px", "easeOutBack"]}, {queue : false, duration : 800});

			}
    		});

	}


/**
   * PK Resize Thumbs
*/

	function pkResizeThumbs() {

		var div = jQuery("#a47_thumbs");
		div.css({ "position" : "absolute", "left" : Math.round((a47_stage_width / 2) - (div.width() / 2)) + "px", "top" : Math.round(a47_stage_height - (div.height() + 80)) + "px" });

	}


/**
   * PK Manage Thumbs
*/

	function pkManageThumbs(actionType, value) {

		if(a47_info_open == true) {

			return true;

		}

		jQuery("#a47_thumbs").show()

		if(actionType == "show") {

			a47_thumbs_open = true;
			jQuery("#a47_thumbs ul").css("position", "absolute").stop().animate({ "top" : 0 + "px" }, 800, "easeOutExpo");

		} else {

			a47_thumbs_open = false;
			jQuery("#a47_thumbs ul").css("position", "absolute").stop().animate({ "top" : value  + "px"}, 800, "easeOutExpo", function() {

				jQuery("#a47_thumbs").hide();

			});

		}

	}


/**
   * PK Png Fix
*/

	function pkPngFix() {
		
		if(jQuery.browser.msie && parseInt(jQuery.browser.version) < 9) {
			jQuery("#a47_gallery li img").css({
		
				"background" : "transparent",
				"-ms-filter": "progid:DXImageTransform.Microsoft.gradient(startColorstr=#00FFFFFF,endColorstr=#00FFFFFF)",   
				"filter" : "progid:DXImageTransform.Microsoft.gradient(startColorstr=#00FFFFFF,endColorstr=#00FFFFFF)",    
				"zoom" : 1
			
			});
		}
				
	}


/**
   * PK Init PrettyPhoto
*/

	function pkInitPrettyPhoto() {

		if(a47_new_type != "video") {
			jQuery("a[data-prettyPhoto^='prettyPhoto']").prettyPhoto({
				default_width:800,
				default_height:450,
				allow_resize: true,
				autoplay_slideshow: false,
				slideshow: 5000,
				opacity: 0.8,
				theme: 'dark_square'
			});
		}

	}


/**
   * PK Change Item
*/

	function pkChangeItem(change_type) {

		var new_mask = jQuery("#a47_gallery ul:first li").filter(":eq(" + a47_new_item + ")");
		var old_mask = jQuery("#a47_gallery ul:first li").filter(":eq(" + a47_old_item + ")");
		var new_image = jQuery("div:first img", new_mask);
		var old_image = jQuery("div:first img", old_mask);
		var new_video = jQuery("div:first", new_mask);
		var old_video = jQuery("div:first", old_mask);
		
		a47_image_width = new_image.width();
		a47_image_height = new_image.height();
		
		(a47_new_type == "image") ? pkResizeObject(new_image, "", "image", new_image.width(), new_image.height(), false) : pkResizeObject(new_video, "", "video", a47_video_width, a47_video_height, false);

		var new_width = (a47_new_type == "image") ? new_image.width() : new_video.width();
		var new_height = (a47_new_type == "image") ? new_image.height() : new_video.height();
		var old_width = (a47_old_type == "image") ? old_image.width() : old_video.width();

		if(change_type == "slide") {

			if(a47_slide_verse == "next") {

				var x_position = (a47_info_open == false) ? (a47_stage_width / 2) + (old_width / 2) + 60 : (a47_stage_width / 2) + (jQuery("#a47_info").width() / 2) + 60;

				old_mask.stop().animate({ "width" : 0 + "px", "left" : Math.round((a47_stage_width / 2) - (new_width / 2) - 60) + "px" }, 800, "easeInOutExpo", function(){ 

					if(a47_old_type == "video") { jQuery(".a47_video", old_mask).empty(); } else { jQuery(".a47_image", old_mask).empty(); }

				});
 				new_mask.css({ "height" : new_height + "px", "left" : Math.round(x_position) + "px", "top" : Math.round((a47_stage_height / 2) - (new_height / 2)) + "px" });
 				new_mask.stop().animate({ "width" : new_width + "px", "left" : Math.round((a47_stage_width / 2) - (new_width / 2)) + "px" }, 800, "easeInOutExpo", function() {

 					if(a47_new_type == "video") { jQuery("#a47_gallery ul:first li").filter(":eq(" + a47_new_item + ")").find(".a47_video").html(a47_media[a47_new_item]); }

					a47_is_loader = false;
					
					pkInitPrettyPhoto();
					pkSlideshow();

				});

			} else {

				var x_position = (a47_info_open == false) ? (a47_stage_width / 2) - (old_width / 2) - 60 : (a47_stage_width / 2) - (jQuery("#a47_info").width() / 2) - 60;

				old_mask.stop().animate({ "width" : 0 + "px", "left" : Math.round((a47_stage_width / 2) + (new_width / 2) + 60) + "px" }, 800, "easeInOutExpo", function(){ 

					if(a47_old_type == "video") { jQuery(".a47_video", old_mask).empty(); } else { jQuery(".a47_image", old_mask).empty(); }

				});
				new_mask.css({ "height" : new_height + "px", "left" : Math.round(x_position) + "px", "top" : Math.round((a47_stage_height / 2) - (new_height / 2)) + "px" });
				new_mask.stop().animate({ "width" : new_width + "px", "left" : Math.round((a47_stage_width / 2) - (new_width / 2)) + "px" }, 800, "easeInOutExpo", function(){

					if(a47_new_type == "video") { jQuery("#a47_gallery ul:first li").filter(":eq(" + a47_new_item + ")").find(".a47_video").html(a47_media[a47_new_item]); }

					a47_is_loader = false;
					
					pkInitPrettyPhoto();
					pkSlideshow();

				});

			}

		} else {

			jQuery("#a47_gallery ul:first li").each(function(i) {

				if(i != a47_new_item) { 

					jQuery(this).css({ "width" : 0 + "px", "left" : "0px" })
					jQuery(".a47_image, .a47_video", this).empty(); 

				}

			});

			new_mask.css({ "width" : new_width + "px", "height" : new_height + "px" });
			if(a47_new_type == "video") { jQuery("#a47_gallery ul:first li").filter(":eq(" + a47_new_item + ")").find(".a47_video").html(a47_media[a47_new_item]); }
			
			pkPositionObject(new_mask);

			setTimeout(function() {
				a47_is_loader = false;
				a47_is_first = false;
				
				pkInitPrettyPhoto();
				pkSlideshow();
			}, 200);

		}

		if(a47_info_open == true) { pkHideInfo("slide"); }
		if(a47_is_slideshow == true) {
			clearInterval(a47_interval);
			jQuery("#a47_slideshow_bar").stop().css({ "width" : 0 + "px" });
		}

		a47_deep_link_change_item = false;

	}


/**
   * PK Slideshow
*/

	function pkSlideshow() {

		clearInterval(a47_interval);

		if(a47_is_slideshow == false || a47_new_type == "video" || jQuery("#a47_gallery ul:first li").length <= 1) {

			return true;

		}

		var bar = jQuery("#a47_slideshow_bar");
		var current_item = jQuery("#a47_gallery ul:first li").filter(":eq(" + a47_new_item + ")");

		bar.css({ "width" : 0 + "px", "top" : Math.round(a47_stage_height - 1) + "px", "left" : "0px"}).show();
		bar.stop().animate({ "width" : a47_stage_width + "px" }, a47_interval_timer, "linear", function() {

			bar.css({ "width" : 0 + "px" });

		});

		a47_interval = setInterval(function() {

		 	clearInterval(a47_interval);
			jQuery("#a47_button_next").trigger("click", [true]);

		}, a47_interval_timer);

	}


/**
   * PK Resize Info
*/

	function pkResizeInfo() {

		pkResizeObject("#a47_info", "", "", "", "", true);
		pkPositionObject("#a47_info");

		jQuery("#a47_info_wrapper").css({ "height" : (jQuery("#a47_info").height() - 80) + "px" });
		var margin_top = Math.round((jQuery("#a47_info_wrapper").height() / 2) - (jQuery("#a47_info_content").height() / 2));
		(margin_top <= 0) ? jQuery("#a47_info_content").css({ "margin-top" : 0 + "px", "width" : 580 + "px" }) : jQuery("#a47_info_content").css({ "margin-top" : margin_top + "px", "width" : 600 + "px" });
		
		jQuery('#a47_info_wrapper').jScrollPane();

	}


/**
   * PK Show Info
*/

	function pkShowInfo() {

		a47_info_open = true;

		pkResizeObject("#a47_info", "", "", "", "", true);
		pkPositionObject("#a47_info");

		var info_width = jQuery("#a47_info").width();
		var current_item = jQuery("#a47_gallery ul:first li").filter(":eq(" + a47_new_item + ")");

		jQuery("#a47_button_info").text(a47_button_info_close_label);

		if(a47_slide_verse == "next") {

			current_item.stop().animate({ "left": Math.round((a47_stage_width / 2) - (info_width / 2)) - 60 + "px", width: 0 + "px" }, 800, "easeInOutExpo");
			jQuery("#a47_info").css({ "left" : Math.round((a47_stage_width / 2) + (current_item.width() / 2)) + 60, "width" : 0 + "px" }).show();
			jQuery("#a47_info").stop().animate({ "left": Math.round((a47_stage_width / 2) - (info_width / 2)) + "px", width: info_width + "px" }, 800, "easeInOutExpo", function() {
				
				if(jQuery.browser.msie && parseInt(jQuery.browser.version) < 9) { pkAttachInfo(); }
				
			});

		} else {

			current_item.stop().animate({ "left": Math.round((a47_stage_width / 2) + (info_width / 2)) + 60 + "px", width: 0 + "px" }, 800, "easeInOutExpo");
			jQuery("#a47_info").css({ "left" : Math.round((a47_stage_width / 2) - (current_item.width() / 2)) - 60, "width" : 0 + "px" }).show();
			jQuery("#a47_info").stop().animate({ "left": Math.round((a47_stage_width / 2) - (info_width / 2)) + "px", width: info_width + "px" }, 800, "easeInOutExpo", function() {
				
				if(jQuery.browser.msie && parseInt(jQuery.browser.version) < 9) { pkAttachInfo(); }
				
			});

		}

		if(!jQuery.browser.msie || (jQuery.browser.msie && parseInt(jQuery.browser.version) >= 9)) { pkAttachInfo(); }

		if(a47_is_slideshow == true) {
			clearInterval(a47_interval);
			jQuery("#a47_slideshow_bar").stop().css({ "width" : 0 + "px" });
		}

	}


/**
   * PK Attach Info
*/

	function pkAttachInfo() {

		jQuery("#a47_info_wrapper, #a47_info_content").remove();
		jQuery("#a47_info").append("<div id='a47_info_wrapper'></div>");
		jQuery("#a47_info_wrapper").append("<div id='a47_info_content'>" + a47_infos[a47_new_item] + "</div>");
		jQuery("#a47_info_wrapper").css({ "margin-top" : 40 + "px" , "height" : (jQuery("#a47_info").height() - 80) + "px" });

		var margin_top = Math.round((jQuery("#a47_info_wrapper").height() / 2) - (jQuery("#a47_info_content").height() / 2));

		(margin_top <= 0) ? jQuery("#a47_info_content").css({ "margin-top" : 0 + "px", "width" : 580 + "px" }) : jQuery("#a47_info_content").css({ "margin-top" : margin_top + "px", "width" : 600 + "px" });
		jQuery('#a47_info_wrapper').jScrollPane();

	}


/**
   * PK Hide Info
*/

	function pkHideInfo(click_type) {

		a47_info_open = false;

		var info_width = jQuery("#a47_info").width();
		var current_item = jQuery("#a47_gallery ul:first li").filter(":eq(" + a47_new_item + ")");
		var current_item_width = (a47_new_type == "image") ? jQuery("div:first img", current_item).width() : jQuery("div:first", current_item).width();

		jQuery("#a47_button_info").text(a47_button_info_open_label);

		if(a47_deep_link_change_item == true) {

			jQuery("#a47_info").stop().css({ "left": Math.round((a47_stage_width / 2) - (current_item_width / 2) - 60) + "px", width: "0px" }).hide();
			jQuery("#a47_info_wrapper").remove();

			return true;

		}

		if(a47_slide_verse == "next") {

			if(click_type == "info") {
				current_item.css({ "left": Math.round((a47_stage_width / 2) + (info_width / 2) + 60) + "px", width: 1 + "px" });
				current_item.stop().animate({ "left" : Math.round((a47_stage_width / 2) - (current_item_width / 2)) + "px", width: current_item_width + "px" }, 800, "easeInOutExpo", function() {

					if(a47_is_slideshow == true && a47_new_type == "image") { pkSlideshow(); }

				});
			}

			jQuery("#a47_info").stop().animate({ "left": Math.round((a47_stage_width / 2) - (current_item_width / 2) - 60) + "px", width: 0 + "px" }, 800, "easeInOutExpo", function() {

				jQuery("#a47_info").hide();
				jQuery("#a47_info_wrapper").remove();

			});

		} else {

			if(click_type == "info") {
				current_item.css({ "left": Math.round((a47_stage_width / 2) - (info_width / 2) - 60) + "px", width: 1 + "px" });
				current_item.stop().animate({ "left" : Math.round((a47_stage_width / 2) - (current_item_width / 2)) + "px", width: current_item_width + "px" }, 800, "easeInOutExpo", function() {

					if(a47_is_slideshow == true && a47_new_type == "image") { pkSlideshow(); }

				});
			}

			jQuery("#a47_info").stop().animate({ "left": Math.round((a47_stage_width / 2) + (current_item_width / 2) + 60) + "px", width: 0 + "px" }, 800, "easeInOutExpo", function() {

				jQuery("#a47_info").hide();
				jQuery("#a47_info_wrapper").remove();

			});

		}

	}

	
/**
   * PK Show Preloader
*/

	function pkShowPreloader() {
		
		jQuery("#a47_gallery").append('<span id="a47_preloader"></span>');
		
		jQuery("#a47_preloader").css({ "left" : ((a47_stage_width / 2) - (jQuery("#a47_preloader").width() / 2)) + "px", "top" : ((a47_stage_height / 2) - (jQuery("#a47_preloader").height() / 2)) + "px" });
		
	}
	

/**
   * PK Hide Preloader
*/

	function pkHidePreloader() {
		
		jQuery("#a47_preloader").remove();
		
	}


/**
   * PK Resize Preloader
*/

	function pkResizePreloader() {
		
		jQuery("#a47_preloader").css({ "left" : ((a47_stage_width / 2) - (jQuery("#a47_preloader").width() / 2)) + "px", "top" : ((a47_stage_height / 2) - (jQuery("#a47_preloader").height() / 2)) + "px" });
		
	}


/**
   * PK Resize Object
*/

	function pkResizeObject(object, object_mask, object_type, width, height, info) {

		var obj = jQuery(object);
		var mask = jQuery(object_mask);

		if(info == false) {

			var max_width = Math.round(jQuery(window).width() - 250);
			var max_height = Math.round(jQuery(window).height() - 180);
			var scaling_factor = Math.min((max_width / width), (max_height / height));

			var w = Math.round(width * scaling_factor);
			var h = Math.round(height * scaling_factor);

			if(object_type == "image") {

				(a47_images_up_scale == false && (w >= a47_image_width || h >= a47_image_height)) ? obj.css({"width" : a47_image_width + "px", "height" : a47_image_height + "px" }) : obj.css({"width" : w + "px", "height" : h + "px" });

			} else {
				
				(a47_videos_up_scale == false && (w >= a47_video_width || h >= a47_video_height)) ? obj.css({"width" : a47_video_width + "px", "height" : a47_video_height + "px" }) : obj.css({"width" : w + "px", "height" : h + "px" });
			}

			mask.css({"width" : obj.width() + "px", "height" : obj.height() + "px"});

		} else {

			var max_width = 910;
			var max_height = Math.round(jQuery(window).height() - 180);

			(max_height >= a47_info_max_height) ? obj.css({ "width" : max_width + "px", "height" : a47_info_max_height + "px" }) : obj.css({ "width" : max_width + "px", "height" : max_height + "px" });

		}

	}


/**
   * PK Position Object
*/

	function pkPositionObject(object, hideObject) {

		var obj = jQuery(object);

		var a47_stage_width = jQuery(window).width();
		var a47_stage_height = jQuery(window).height();

		if(hideObject == true) {
			
			obj.css({"position" : "absolute", "left" : "-5px", "top" : (a47_stage_height / 2) - (obj.height() / 2) });
			
		} else {
			
			obj.css({"position" : "absolute", "left" : (a47_stage_width / 2) - (obj.width() / 2), "top" : (a47_stage_height / 2) - (obj.height() / 2) });
			
		}

	}


/**
   * PK Update Counter
*/

	function pkUpDateCounter(current, total) {

		var current_number = ((current + 1) <= 9) ? "0" + (current + 1) : (current + 1);
		var total_number = (total <= 9) ? "0" + total : total;

		jQuery("#a47_count").text(current_number + "/" + total_number);

	}
