﻿function getIlan() {
    _set_interface(function() {
		$('#lightbox-container-form-box').css( { width: "322px", height: "458px" } );
        $('#lightbox-container-form').html("<a href='javascript:_finish()'><img src='images/closelabel.gif' alt='Kapat' style='float:right;' /></a><br /><a href='http://www.balparmak.com.tr/kurumsal.gorseller.basin.bultenleri.asp#53'><img src='images/ana_sayfa_ilan.jpg' alt='' /></a>");
		//_center_lightbox();
		setTimeout(function(){ _finish(); }, 10 * 1000);
    });
}

var settings = jQuery.extend({ 
    overlayBgColor: '#000',
    overlayOpacity: 0.8,
    fixedNavigation: false,
    imageLoading: 'images/lightbox-ico-loading.gif',
    imageBtnClose: 'images/lightbox-btn-close.gif',
    imageBlank: 'images/lightbox-blank.gif',
    containerBorderSize: 10,
    containerResizeSpeed: 400
});

function _center_lightbox() {
    /*var LightboxHeight = $('#jquery-lightbox') ? $('#jquery-lightbox').height() : null;
    var WindowHeight = $(window) ? $(window).height() : null;
    $('#jquery-lightbox').css({ top: ((WindowHeight - LightboxHeight) / 2) + window.pageYOffset });*/
}

function _set_interface(Callback) {
	$('embed, object, select').css({'visibility':'hidden'});
    $('body').append('<div id="jquery-overlay"></div><div id="jquery-lightbox"><div id="lightbox-container-form-box"><div id="lightbox-container-form"></div></div></div>');
    var arrPageSizes = ___getPageSize();
    $('#jquery-overlay').css({ backgroundColor: settings.overlayBgColor,
        opacity: settings.overlayOpacity,
        width: arrPageSizes[0],
        height: arrPageSizes[1]
    }).fadeIn(function() { if (Callback != null) { Callback.call(); _center_lightbox(); } });
    var arrPageSizes = ___getPageSize();
    var arrPageScroll = ___getPageScroll();
    $('#jquery-lightbox').css({ top: (arrPageSizes[3] - arrayPageSize[4]) / 2 /*arrPageScroll[1] + (arrPageSizes[3] / 9)*/, left: arrPageScroll[0] }).show(function() { _center_lightbox(); });
    $('#lightbox-container-form-box').click(function(event) {
        event.stopPropagation();
        if (event.target.id == "btn_close")
            _finish();
    });
    $('#jquery-overlay,#jquery-lightbox').click(function() {
        _finish();
    });
    $(window).resize(function() {
        var arrPageSizes = ___getPageSize();
        $('#jquery-overlay').css({ width: arrPageSizes[0], height: arrPageSizes[1] });
        var arrPageScroll = ___getPageScroll();
        $('#jquery-lightbox').css({ top: (arrPageSizes[3] - arrayPageSize[4]) / 2 /*arrPageScroll[1] + (arrPageSizes[3] / 9)*/, left: arrPageScroll[0] });
    });
}

function _finish(){
    $('#jquery-lightbox').remove();
    $('#jquery-overlay').fadeOut(function(){$('#jquery-overlay').remove();});
    $('embed, object, select').css({'visibility':'visible'});
}

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;
    }
    var LightboxHeight = $('#jquery-lightbox') ? $('#jquery-lightbox').height() : null;
    var DocumentHeight = $(document) ? $(document).height() : null;
    arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight, LightboxHeight);
    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;
};
