﻿// JavaScript Document

var $orvof = jQuery.noConflict();
var expandAllOpen = false;
var $oldPosition = 0;
var currentCulture = "";
var currentPageURL = "";
var currentModelShortName = "";
var mediaType = "";
var currentAccordionType = "";
var tagSectionType = "";
var tagAccID = "";
var accessoryBuildLinkCurrURL = "";
var accessoryMoreInfoLinkCurrURL = "";

$orvof(document).ready(orvof_READY);

function orvof_READY() {
	orvof_bind_events();
	modPop_bind_events();
};


function orvof_bind_events() {
	$orvof('.accordionHeader').click(orvof_accHeader_CLICK);
	$orvof('#accordionTopBarActionText').click(expandAll_CLICK);
	$orvof('.lightboxPhoto').lightBox();
	$orvof('.accessoryItem').bind('click', accessoryDetail_CLICK);
	
	$orvof('#popupBlind').after($orvof('#orv-overivew-featured-accessories-details'));
	$orvof('.orv-accessory-details-close-button').click(popupBlind_CLICK);
	
	// Set the current culture
	var currentURL = document.location.href;
	if (currentURL.indexOf("en-us") > -1) {
		currentCulture = "en-us";
	}
	if (currentURL.indexOf("en-ca") > -1) {
		currentCulture = "en-ca";
	}
	if (currentURL.indexOf("fr-ca") > -1) {
		currentCulture = "fr-ca";
	}
	
	var startPos = currentURL.indexOf(currentCulture);
	currentPageURL = currentURL.substring(startPos - 1, currentURL.indexOf(".aspx"));
	
	currentModelShortName = $orvof('.overviewFeaturesWrapper').attr('id');
	
	accessoryBuildLinkCurrURL = $orvof('.orv-accessory-build-link').attr('href');
	accessoryMoreInfoLinkCurrURL = $orvof('.orv-accessory-details-link').attr('href');
	accessoryBigBuildLinkClick();
	
	$orvof('#getQuoteBtn > a').click(getQuoteBtn_CLICK);
	$orvof('#buildModelBtn > a').click(buildModelBtn_CLICK);
	
}

function modPop_bind_events(){
	$orvof('.accordionContentActionBtn').click(mediaPopup_CLICK);
	$orvof('#popupBlind').click(popupBlind_CLICK);
}

function orvof_accHeader_CLICK() {
	var contentBody = $orvof(this).next('.accordionContent');
	var currentValue = $orvof(this).next('.accordionContent').css('display');
	currentAccordionType = $orvof(this).attr('id');
	
	var showText = $orvof(this).children('.accordionHeaderActionText').attr('showText');
	var hideText = $orvof(this).children('.accordionHeaderActionText').attr('hideText');

	$orvof('img', contentBody).each(function(index){
		var newSource = $orvof(this).attr("imageSrc");
		$orvof(this).attr("src", newSource);
	});

	if (currentValue == "none") {
		$orvof(contentBody).show();
		$orvof(this).children('.accordionIcon').css('background-position', '-15px 0px');
		$orvof(this).children('.accordionHeaderActionText').text(hideText);
		
		var openTag = "DCS.dcsuri," + currentPageURL + "/html_ov_show_" + currentAccordionType + ",WT.si_n,ORV-ov_show_" + currentAccordionType + "_" + currentModelShortName + ",WT.si_x,1";
		fireTag(openTag);
		
	} else {
		$orvof(contentBody).hide();
		$orvof(this).children('.accordionIcon').css('background-position', '0px 0px');
		$orvof(this).children('.accordionHeaderActionText').text(showText);
		
		var openTag = "DCS.dcsuri," + currentPageURL + "/html_ov_hide_" + currentAccordionType + ",WT.si_n,ORV-ov_hide_" + currentAccordionType + "_" + currentModelShortName + ",WT.si_x,1";
		fireTag(openTag);

	}
}

function orvof_accHeader_expand(item) {
	var contentBody = $orvof(item).next('.accordionContent');
	var currentValue = $orvof(item).next('.accordionContent').css('display');
	
	var showText = $orvof(item).children('.accordionHeaderActionText').attr('showText');
	var hideText = $orvof(item).children('.accordionHeaderActionText').attr('hideText');

	$orvof('img', contentBody).each(function(index){
		var newSource = $orvof(this).attr("imageSrc");
		$orvof(this).attr("src", newSource);
	});

	if (currentValue == "none" && expandAllOpen == false) {
		$orvof(contentBody).show();
		$orvof(item).children('.accordionIcon').css('background-position', '-15px 0px');
		$orvof(item).children('.accordionHeaderActionText').text(hideText);
		
		
	} else if (expandAllOpen == true) {
		$orvof(contentBody).hide();
		$orvof(item).children('.accordionIcon').css('background-position', '0px 0px');
		$orvof(item).children('.accordionHeaderActionText').text(showText);
	}
}


function popupBlind_CLICK() {
	if( jwplayer() !== undefined ){
		jwplayer().onReady( function(){
			jwplayer().stop();
		});
		jwplayer().stop();
	}
	
	if (mediaType == 'video') {
		$orvof('#global_video_player_container, #popupBlind, #image_viewer, #orv-overivew-featured-accessories-details').fadeOut( function(){
			$orvof('#global_video_player').empty();
		});
		var closeVideoTag = "DCS.dcsuri," + currentPageURL + "/html_ov_" + tagSectionType + "_video_close_" + currentModelShortName + ",WT.si_n,ORV-ov_" + tagSectionType + "_video_close_" + currentModelShortName + ",WT.si_x,1";
		fireTag(closeVideoTag);
	}
	if (mediaType == 'photo') {
		// See function below		
	}
	if (mediaType == 'accessory') {
		$orvof('#orv-overivew-featured-accessories-details').fadeOut();
		var closeAccTag = "DCS.dcsuri," + currentPageURL + "/html_ov_accessory_close_detail_" + tagAccID + ",WT.si_n,ORV-ov_accessory_close_" + currentModelShortName + "_" + tagAccID + ",WT.si_x,1";
		fireTag(closeAccTag);
	}
	
	$orvof('#popupBlind').fadeOut();
}

function fireClosePhotoTag() {
	var closePhotoTag = "DCS.dcsuri," + currentPageURL + "/html_ov_" + tagSectionType + "_photo_close,WT.si_n,ORV-ov_" + tagSectionType + "_photo_close_" + currentModelShortName + ",WT.si_x,1";
	fireTag(closePhotoTag);
}

function mediaPopup_CLICK() {
	mediaType = $orvof(this).attr('type');
	var vidName = $orvof(this).attr('title');
	var vidDesc = $orvof(this).attr('desc');
	
	tagSectionType = $orvof(this).attr('id');
	
	if (mediaType == 'video') {
		
		var videoLink = $orvof(this).attr('link');		
		if( $orvof('#global_video_player').parent().attr( 'id' ) != "global_video_player_container" ) {
			$orvof('#global_video_player').wrap( '<div id="global_video_player_container" />' );
		}
		showVideo(videoLink, vidName, vidDesc);
		
		var arrPageSizes = getPageSize();
		var arrPageScroll = getPageScroll();
	
		$orvof('#global_video_player_container').css({
		    top: arrPageScroll[1] + (arrPageSizes[3] / 10),
		    'margin-left': '-359px'
		}).fadeIn();
	
		$orvof('#popupBlind').css({
		    backgroundColor: '#000',
		    opacity: 0.8,
		    width: arrPageSizes[0],
		    height: arrPageSizes[1]
		}).fadeIn();

		$orvof('#popupBlind').fadeTo('fast', .8);
		
		var videoViewTag = "DCS.dcsuri," + currentPageURL + "/html_ov_" + tagSectionType + "_video_view_" + vidName.replace(/ /g, "_") + ",WT.si_n,ORV-ov_" + tagSectionType + "_video_" + currentModelShortName + "_" + vidName.replace(/ /g, "_") + ",WT.si_x,1";
		fireTag(videoViewTag);
	
	} else if (mediaType == 'photo') {
		// Lightbox handles this.
		var showPhotoTag = "DCS.dcsuri," + currentPageURL + "/html_ov_" + tagSectionType + "_photo_view_" + vidName.replace(/ /g, "_") + ",WT.si_n,ORV-ov_" + tagSectionType + "_photo_" + currentModelShortName + "_" + vidName.replace(/ /g, "_") + ",WT.si_x,1";
		fireTag(showPhotoTag);
	}
	
}

function expandAll_CLICK() {
	var currentValue = $orvof('#accordionTopBarActionText').text();
	var newValue = $orvof('#accordionTopBarActionText').attr('altValue');	
	
	if (expandAllOpen == false) {
		$orvof('.accordionHeader').each(function() {
			orvof_accHeader_expand(this);
		});
		expandAllOpen = true;		
		var showAllTag = "DCS.dcsuri," + currentPageURL + "/html_ov_show_all,WT.si_n,ORV-ov_show_all_" + currentModelShortName + ",WT.si_x,1";
		fireTag(showAllTag);
	} else {
		$orvof('.accordionHeader').each(function() {
			orvof_accHeader_expand(this);
		});
		expandAllOpen = false;
		var hideAllTag = "DCS.dcsuri," + currentPageURL + "/html_ov_hide_all,WT.si_n,ORV-ov_hide_all_" + currentModelShortName + ",WT.si_x,1";
		fireTag(hideAllTag);
	}
	$orvof('#accordionTopBarActionText').text(newValue);
	$orvof('#accordionTopBarActionText').attr('altValue', currentValue);
}

// Video Player
function showVideo(path, vidName, vidDesc) {

	jwplayer('global_video_player').setup({
		flashplayer: '/ScriptSite/jwPlayer/player.swf',
       	file: path,
		autostart: true,
    	controlbar: 'bottom',
    	width: 718,
    	height: 390,
    	stretching: 'exactfit',
    	events: {
			'onComplete': function(){
				popupBlind_CLICK();
			},
			'onFullscreen': function(event) {
				if (event.fullscreen == true) {
					var toFullScreenTag = "DCS.dcsuri," + currentPageURL + "/html_ov_" + tagSectionType + "_video_full_screen,WT.si_n,ORV-ov_" + tagSectionType + "_video_full_screen_" + currentModelShortName + ",WT.si_x,1";
					fireTag(toFullScreenTag);
				} else {
					var toNormalScreenTag = "DCS.dcsuri," + currentPageURL + "/html_ov_" + tagSectionType + "_video_reg_screen,WT.si_n,ORV-ov_" + tagSectionType + "_video_reg_screen_" + currentModelShortName + ",WT.si_x,1";
					fireTag(toNormalScreenTag);
				}
			},
			'onMute': function(event) {
				if (event.mute == true) {
					var muteOnTag = "DCS.dcsuri," + currentPageURL + "/html_ov_" + tagSectionType + "_video_sound_off,WT.si_n,ORV-ov_" + tagSectionType + "_video_sound_off_" + currentModelShortName + ",WT.si_x,1";
					fireTag(muteOnTag);
				} else {
					var muteOffTag = "DCS.dcsuri," + currentPageURL + "/html_ov_" + tagSectionType + "_video_sound_on,WT.si_n,ORV-ov_" + tagSectionType + "_video_sound_on_" + currentModelShortName + ",WT.si_x,1";
					fireTag(muteOffTag);
				}
			},
			'onPause': function() {
				var pauseTag = "DCS.dcsuri," + currentPageURL + "/html_ov_" + tagSectionType + "_video_pause_video,WT.si_n,ORV-ov_" + tagSectionType + "_video_pause_video_" + currentModelShortName + ",WT.si_x,1";
				fireTag(pauseTag);	
			},
			'onPlay': function(event) {
				if (event.oldstate == "PAUSED") {
					var playTag = "DCS.dcsuri," + currentPageURL + "/html_ov_" + tagSectionType + "_video_play_video,WT.si_n,ORV-ov_" + tagSectionType + "_video_play_video_" + currentModelShortName + ",WT.si_x,1";
					fireTag(playTag);	
				}
			},
			'onSeek': function() {
				var seekTag = "DCS.dcsuri," + currentPageURL + "/html_ov_" + tagSectionType + "_video_move_scrub_bar,WT.si_n,ORV-ov_" + tagSectionType + "_video_move_scrub_bar_" + currentModelShortName + ",WT.si_x,1";
				fireTag(seekTag);
			}
		}
    });
        
    if ($orvof('#videoInfoBox').length == 0) {
        
    	$prepend  = "<div id='videoTitleBox'><div id='videoTitleBoxText'></div><div id='closeBtn'><img src='/StyleSite/ORV/2012/images/close_btn.png'/></div>";
    	$append = "<div id='videoInfoBox'></div>";	
    	$orvof('#global_video_player_container').prepend("<div id='videoTitleBox'><div id='videoTitleBoxText'></div><div id='closeBtn'><img src='/StyleSite/ORV/2012/images/close_btn.png'/></div><div class='clearing'></div></div>");
    	$orvof('#global_video_player_container').append("<div id='videoInfoBox'></div>");	
    }
        
    $orvof('#global_video_player').css('display','block');
    $orvof('#videoInfoBox').html(vidDesc);
    $orvof('#videoTitleBoxText').html(vidName);
    $orvof('#closeBtn').click(popupBlind_CLICK);

}

function accessoryDetail_CLICK() {
	mediaType = "accessory";
	var thumbImage = $orvof('.accessoryDetailLink > img', this).attr('src');
	var partNumbersData = $orvof('.partNumbers', this).text();
	
	$orvof('.orv-accessory-details-title').text($orvof('.orv-fa-heading', this).text());
	$orvof('.orv-accessory-details-subtitle').text(partNumbersData);
	$orvof('.orv-accessory-details-price').text($orvof('.price', this).text());		
	$orvof('.orv-accessory-details-description').html($orvof('.desc', this).html());
	$orvof('.orv-accessory-details-image').attr('src', thumbImage);
	$orvof('.orv-accessory-details-link').attr('href', $orvof('.link', this).text());
	$orvof('.orv-accessory-build-link').attr('href', $orvof('.buildLink', this).text());
	
	
	var arrPageSizes = getPageSize();
	
	$orvof('#popupBlind').css({
	    backgroundColor: '#000',
	    opacity: 0.8,
	    width: arrPageSizes[0],
	    height: arrPageSizes[1]
	}).fadeIn();
	
	var arrPageScroll = getPageScroll();
	
	$orvof('#orv-overivew-featured-accessories-details').css({
	    top: arrPageScroll[1] + (arrPageSizes[3] / 10)
	    //left: arrPageScroll[0]
	}).show();
	
	
	$orvof(window).resize(function () {
		var arrPageSizes = getPageSize();
		$orvof('#popupBlind').css({
			width: arrPageSizes[0],
			height: arrPageSizes[1]
		});
		var arrPageScroll = getPageScroll();
		$orvof('#orv-overivew-featured-accessories-details').css({
			top: arrPageScroll[1] + (arrPageSizes[3] / 10)
			//left: arrPageScroll[0]
		});
	});
	$orvof('#orv-overivew-featured-accessories-details').fadeIn();

	// Below is for tagging
	tagAccID = partNumbersData.replace(/,/g, "_").replace(/ /g, "").replace(/#/g, "");
	var openAccDetailTag = "DCS.dcsuri," + currentPageURL + "/html_ov_accessory_open_detail_" + tagAccID + ",WT.si_n,ORV-ov_accessory_open_" + currentModelShortName + "_" + tagAccID + ",WT.si_x,1";
	fireTag(openAccDetailTag);
	
	mediaType = "accessory";
	accessoryBuildLinkClick();
	accessoryMoreInfoLinkClick();
}


function getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight) {
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else {
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {
		if (document.documentElement.clientWidth) {
			windowWidth = document.documentElement.clientWidth;
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	if (yScroll < windowHeight) {
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}
	if (xScroll < windowWidth) {
		pageWidth = xScroll;
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight);
	return arrayPageSize;
};

function getPageScroll() {
    var xScroll, yScroll;
    if (self.pageYOffset) {
        yScroll = self.pageYOffset;
        xScroll = self.pageXOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {
        yScroll = document.documentElement.scrollTop;
        xScroll = document.documentElement.scrollLeft;
    } else if (document.body) {
        yScroll = document.body.scrollTop;
        xScroll = document.body.scrollLeft;
    }
    arrayPageScroll = new Array(xScroll, yScroll);
    return arrayPageScroll;
};

function accessoryBuildLinkClick() {
	var accBuildLinkTag = "?WT.si_n=ORV-ov_accessory_build_" + currentModelShortName + "_" + tagAccID + "&WT.si_x=1";
	$orvof('.orv-accessory-build-link').attr('href', accessoryBuildLinkCurrURL + accBuildLinkTag);
}

function accessoryBigBuildLinkClick() {
	var accBuildLinkTag = "?WT.si_n=ORV-ov_accessory_build_" + currentModelShortName + "&WT.si_x=1";
	var currURL = $orvof('#orv-accessory-big-build-link').attr('href').split("?")[0];
	$orvof('#orv-accessory-big-build-link').attr('href', currURL + accBuildLinkTag)
}

function accessoryMoreInfoLinkClick() {
	var accInfoLinkTag = "?WT.si_n=ORV-ov_accessory_" + currentModelShortName + "&WT.si_x=1";
	$orvof('.orv-accessory-details-link').attr('href', accessoryMoreInfoLinkCurrURL + accInfoLinkTag);
}

function fireTag(tagString) {
	try {
		WTExternalBridge('dcsMultiTrack', tagString);
	} catch(e) {
	}
}

function getQuoteBtn_CLICK() {
	var accBuildLinkTag = "DCS.dcsuri," + currentPageURL + "/html_ov_get_quote_btn,WT.si_n,ORV-ov_get_quote_btn_" + currentModelShortName + ",WT.si_x,1";
	fireTag(accBuildLinkTag);
}

function buildModelBtn_CLICK() {
	var accBuildLinkTag = "DCS.dcsuri," + currentPageURL + "/html_ov_build_model_btn,WT.si_n,ORV-ov_build_model_btn_" + currentModelShortName + ",WT.si_x,1";
	fireTag(accBuildLinkTag);
}

// Lightbox Plugin

(function ($) {
    $.fn.lightBox = function (settings) {
        settings = jQuery.extend({
            overlayBgColor: '#000',
            overlayOpacity: 0.8,
            fixedNavigation: false,
            imageLoading: '/StyleSite/ORV/2012/images/lightbox-ico-loading.gif',
            imageBtnPrev: 'images/lightbox-btn-prev.gif',
            imageBtnNext: 'images/lightbox-btn-next.gif',
            imageBtnClose: '/StyleSite/ORV/2012/images/close_btn.png',
            imageBlank: 'images/lightbox-blank.gif',
            containerBorderSize: 10,
            containerResizeSpeed: 300,
            txtImage: 'Image',
            txtOf: 'of',
            keyToClose: 'c',
            keyToPrev: 'p',
            keyToNext: 'n',
            imageArray: [],
            activeImage: 0
        }, settings);
        var jQueryMatchedObj = this;

        function _initialize() {
            _start(this, jQueryMatchedObj);
            return false;
        }

        function _start(objClicked, jQueryMatchedObj) {
            $('embed, object, select').css({
                'visibility': 'hidden'
            });
            _set_interface();
            settings.imageArray.length = 0;
            settings.activeImage = 0;
            if (jQueryMatchedObj.length == 1) {
                settings.imageArray.push(new Array(objClicked.getAttribute('link'), objClicked.getAttribute('title')));
            } else {
                for (var i = 0; i < jQueryMatchedObj.length; i++) {
                    settings.imageArray.push(new Array(jQueryMatchedObj[i].getAttribute('link'), jQueryMatchedObj[i].getAttribute('title'), jQueryMatchedObj[i].getAttribute('desc')));
                }
            }
            while (settings.imageArray[settings.activeImage][0] != objClicked.getAttribute('link')) {
                settings.activeImage++;
            }
            _set_image_to_view();
        }

        function _set_interface() {
            $('body').append('<div id="jquery-overlay"></div><div id="jquery-lightbox"><div id="lightbox-container-image-box"><div id="lightbox-container-image"><div id="lightbox-title-box"><div id="photoTitleBoxText"></div><div id="closeBtn"><img src="/StyleSite/ORV/2012/images/close_btn.png"/></div><div class="clearing"></div></div><img id="lightbox-image"><div style="" id="lightbox-nav"><a href="#" id="lightbox-nav-btnPrev"></a><a href="#" id="lightbox-nav-btnNext"></a></div><div id="lightbox-loading"><a href="#" id="lightbox-loading-link"><img src="' + settings.imageLoading + '"></a></div></div></div><div id="lightbox-container-image-data-box"><div id="lightbox-container-image-data"><div id="lightbox-image-details"><span id="lightbox-image-details-caption"></span><span id="lightbox-image-details-currentNumber"></span></div><div id="lightbox-secNav"></div></div></div></div>');
            var arrPageSizes = ___getPageSize();
            $('#jquery-overlay').css({
                backgroundColor: settings.overlayBgColor,
                opacity: settings.overlayOpacity,
                width: arrPageSizes[0],
                height: arrPageSizes[1]
            }).fadeIn();
            var arrPageScroll = ___getPageScroll();
            $('#jquery-lightbox').css({
                top: arrPageScroll[1] + (arrPageSizes[3] / 10),
                left: arrPageScroll[0]
            }).show();
            $('#jquery-overlay,#jquery-lightbox').click(function () {
                _finish();
            });
            $('#lightbox-loading-link,#lightbox-secNav-btnClose').click(function () {
                _finish();
                return false;
            });
            $(window).resize(function () {
                var arrPageSizes = ___getPageSize();
                $('#jquery-overlay').css({
                    width: arrPageSizes[0],
                    height: arrPageSizes[1]
                });
                var arrPageScroll = ___getPageScroll();
                $('#jquery-lightbox').css({
                    top: arrPageScroll[1] + (arrPageSizes[3] / 10),
                    left: arrPageScroll[0]
                });
            });
        }

        function _set_image_to_view() {
            $('#lightbox-loading').show();
            if (settings.fixedNavigation) {
                $('#lightbox-image,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber').hide();
            } else {
                $('#lightbox-image,#lightbox-nav,#lightbox-nav-btnPrev,#lightbox-nav-btnNext,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber').hide();
            }
            var objImagePreloader = new Image();
            objImagePreloader.onload = function () {
                $('#lightbox-image').attr('src', settings.imageArray[settings.activeImage][0]);
                _resize_container_image_box(objImagePreloader.width, objImagePreloader.height);
                objImagePreloader.onload = function () {};
            };
            objImagePreloader.src = settings.imageArray[settings.activeImage][0];
        };

        function _resize_container_image_box(intImageWidth, intImageHeight) {
            var intCurrentWidth = $('#lightbox-container-image-box').width();
            var intCurrentHeight = $('#lightbox-container-image-box').height();
            var intWidth = (intImageWidth + (settings.containerBorderSize * 2));
            var intHeight = (intImageHeight + (settings.containerBorderSize * 2) + 20);
            var intDiffW = intCurrentWidth - intWidth;
            var intDiffH = intCurrentHeight - intHeight;
            $('#lightbox-container-image-box').animate({
                width: intWidth,
                height: intHeight
            }, settings.containerResizeSpeed, function () {
                _show_image();
            });
            if ((intDiffW == 0) && (intDiffH == 0)) {
                if ($.browser.msie) {
                    ___pause(250);
                } else {
                    ___pause(100);
                }
            }
            $('#lightbox-container-image-data-box').css({
                width: intImageWidth
            });
            $('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({
                height: intImageHeight + (settings.containerBorderSize * 2)
            });
        };

        function _show_image() {
            $('#lightbox-loading').hide();
            $('#lightbox-image').fadeIn(function () {
                _show_image_data();
            });
            _preload_neighbor_images();
        };

        function _show_image_data() {
            $('#lightbox-container-image-data-box').slideDown('fast');
            $('#lightbox-image-details-caption').hide();
            if (settings.imageArray[settings.activeImage][1]) {
                $('#lightbox-image-details-caption').html(settings.imageArray[settings.activeImage][2]).show();
            }
            $('#photoTitleBoxText').html(settings.imageArray[settings.activeImage][1]);

            //if(settings.imageArray.length>1){$('#lightbox-image-details-currentNumber').html(settings.txtImage+' '+(settings.activeImage+1)+' '+settings.txtOf+' '+settings.imageArray.length).show();}
        }

        function _set_navigation() {
            $('#lightbox-nav').show();
            $('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({
                'background': 'transparent url(' + settings.imageBlank + ') no-repeat'
            });
            if (settings.activeImage != 0) {
                if (settings.fixedNavigation) {
                    $('#lightbox-nav-btnPrev').css({
                        'background': 'url(' + settings.imageBtnPrev + ') left 15% no-repeat'
                    }).unbind().bind('click', function () {
                        settings.activeImage = settings.activeImage - 1;
                        _set_image_to_view();
                        return false;
                    });
                } else {
                    $('#lightbox-nav-btnPrev').unbind().hover(function () {
                        $(this).css({
                            'background': 'url(' + settings.imageBtnPrev + ') left 15% no-repeat'
                        });
                    }, function () {
                        $(this).css({
                            'background': 'transparent url(' + settings.imageBlank + ') no-repeat'
                        });
                    }).show().bind('click', function () {
                        settings.activeImage = settings.activeImage - 1;
                        _set_image_to_view();
                        return false;
                    });
                }
            }
            if (settings.activeImage != (settings.imageArray.length - 1)) {
                if (settings.fixedNavigation) {
                    $('#lightbox-nav-btnNext').css({
                        'background': 'url(' + settings.imageBtnNext + ') right 15% no-repeat'
                    }).unbind().bind('click', function () {
                        settings.activeImage = settings.activeImage + 1;
                        _set_image_to_view();
                        return false;
                    });
                } else {
                    $('#lightbox-nav-btnNext').unbind().hover(function () {
                        $(this).css({
                            'background': 'url(' + settings.imageBtnNext + ') right 15% no-repeat'
                        });
                    }, function () {
                        $(this).css({
                            'background': 'transparent url(' + settings.imageBlank + ') no-repeat'
                        });
                    }).show().bind('click', function () {
                        settings.activeImage = settings.activeImage + 1;
                        _set_image_to_view();
                        return false;
                    });
                }
            }
            _enable_keyboard_navigation();
        }

        function _enable_keyboard_navigation() {
            $(document).keydown(function (objEvent) {
                _keyboard_action(objEvent);
            });
        }

        function _disable_keyboard_navigation() {
            $(document).unbind();
        }

        function _keyboard_action(objEvent) {
            if (objEvent == null) {
                keycode = event.keyCode;
                escapeKey = 27;
            } else {
                keycode = objEvent.keyCode;
                escapeKey = objEvent.DOM_VK_ESCAPE;
            }
            key = String.fromCharCode(keycode).toLowerCase();
            if ((key == settings.keyToClose) || (key == 'x') || (keycode == escapeKey)) {
                _finish();
            }
            if ((key == settings.keyToPrev) || (keycode == 37)) {
                if (settings.activeImage != 0) {
                    settings.activeImage = settings.activeImage - 1;
                    _set_image_to_view();
                    _disable_keyboard_navigation();
                }
            }
            if ((key == settings.keyToNext) || (keycode == 39)) {
                if (settings.activeImage != (settings.imageArray.length - 1)) {
                    settings.activeImage = settings.activeImage + 1;
                    _set_image_to_view();
                    _disable_keyboard_navigation();
                }
            }
        }

        function _preload_neighbor_images() {
            if ((settings.imageArray.length - 1) > settings.activeImage) {
                objNext = new Image();
                objNext.src = settings.imageArray[settings.activeImage + 1][0];
            }
            if (settings.activeImage > 0) {
                objPrev = new Image();
                objPrev.src = settings.imageArray[settings.activeImage - 1][0];
            }
        }

        function _finish() {
            $('#jquery-lightbox').remove();
            $('#jquery-overlay').fadeOut(function () {
                $('#jquery-overlay').remove();
            });
            $('embed, object, select').css({
                'visibility': 'visible'
            });
            
            fireClosePhotoTag();
        }

        function ___getPageSize() {
            var xScroll, yScroll;
            if (window.innerHeight && window.scrollMaxY) {
                xScroll = window.innerWidth + window.scrollMaxX;
                yScroll = window.innerHeight + window.scrollMaxY;
            } else if (document.body.scrollHeight > document.body.offsetHeight) {
                xScroll = document.body.scrollWidth;
                yScroll = document.body.scrollHeight;
            } else {
                xScroll = document.body.offsetWidth;
                yScroll = document.body.offsetHeight;
            }
            var windowWidth, windowHeight;
            if (self.innerHeight) {
                if (document.documentElement.clientWidth) {
                    windowWidth = document.documentElement.clientWidth;
                } else {
                    windowWidth = self.innerWidth;
                }
                windowHeight = self.innerHeight;
            } else if (document.documentElement && document.documentElement.clientHeight) {
                windowWidth = document.documentElement.clientWidth;
                windowHeight = document.documentElement.clientHeight;
            } else if (document.body) {
                windowWidth = document.body.clientWidth;
                windowHeight = document.body.clientHeight;
            }
            if (yScroll < windowHeight) {
                pageHeight = windowHeight;
            } else {
                pageHeight = yScroll;
            }
            if (xScroll < windowWidth) {
                pageWidth = xScroll;
            } else {
                pageWidth = windowWidth;
            }
            arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight);
            return arrayPageSize;
        };

        function ___getPageScroll() {
            var xScroll, yScroll;
            if (self.pageYOffset) {
                yScroll = self.pageYOffset;
                xScroll = self.pageXOffset;
            } else if (document.documentElement && document.documentElement.scrollTop) {
                yScroll = document.documentElement.scrollTop;
                xScroll = document.documentElement.scrollLeft;
            } else if (document.body) {
                yScroll = document.body.scrollTop;
                xScroll = document.body.scrollLeft;
            }
            arrayPageScroll = new Array(xScroll, yScroll);
            return arrayPageScroll;
        };

        function ___pause(ms) {
            var date = new Date();
            curDate = null;
            do {
                var curDate = new Date();
            }
            while (curDate - date < ms);
        };
        return this.unbind('click').click(_initialize);
    };
})(jQuery);
