/* Copyright (c) 2007 Paul Bakaus (paul.bakaus@googlemail.com) and Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * $LastChangedDate: 2007-12-20 08:43:48 -0600 (Thu, 20 Dec 2007) $
 * $Rev: 4257 $
 *
 * Version: 1.2
 *
 * Requires: jQuery 1.2+
 */
 
 		
(function($){
    $.dimensions = {
        version: '1.2'
    };
    $.each(['Height', 'Width'], function(i, name){
        $.fn['inner' + name] = function(){
            if (!this[0]) 
                return;
            var torl = name == 'Height' ? 'Top' : 'Left', borr = name == 'Height' ? 'Bottom' : 'Right';
            return this.is(':visible') ? this[0]['client' + name] : num(this, name.toLowerCase()) + num(this, 'padding' + torl) + num(this, 'padding' + borr);
        };
        $.fn['outer' + name] = function(options){
            if (!this[0]) 
                return;
            var torl = name == 'Height' ? 'Top' : 'Left', borr = name == 'Height' ? 'Bottom' : 'Right';
            options = $.extend({
                margin: false
            }, options ||
            {});
            var val = this.is(':visible') ? this[0]['offset' + name] : num(this, name.toLowerCase()) + num(this, 'border' + torl + 'Width') + num(this, 'border' + borr + 'Width') + num(this, 'padding' + torl) + num(this, 'padding' + borr);
            return val + (options.margin ? (num(this, 'margin' + torl) + num(this, 'margin' + borr)) : 0);
        };
    });
    $.each(['Left', 'Top'], function(i, name){
        $.fn['scroll' + name] = function(val){
            if (!this[0]) 
                return;
            return val != undefined ? this.each(function(){
                this == window || this == document ? window.scrollTo(name == 'Left' ? val : $(window)['scrollLeft'](), name == 'Top' ? val : $(window)['scrollTop']()) : this['scroll' + name] = val;
            }) : this[0] == window || this[0] == document ? self[(name == 'Left' ? 'pageXOffset' : 'pageYOffset')] || $.boxModel && document.documentElement['scroll' + name] || document.body['scroll' + name] : this[0]['scroll' + name];
        };
    });
    $.fn.extend({
        position: function(){
            var left = 0, top = 0, elem = this[0], offset, parentOffset, offsetParent, results;
            if (elem) {
                offsetParent = this.offsetParent();
                offset = this.offset();
                parentOffset = offsetParent.offset();
                offset.top -= num(elem, 'marginTop');
                offset.left -= num(elem, 'marginLeft');
                parentOffset.top += num(offsetParent, 'borderTopWidth');
                parentOffset.left += num(offsetParent, 'borderLeftWidth');
                results = {
                    top: offset.top - parentOffset.top,
                    left: offset.left - parentOffset.left
                };
            }
            return results;
        },
        offsetParent: function(){
            var offsetParent = this[0].offsetParent;
            while (offsetParent && (!/^body|html$/i.test(offsetParent.tagName) && $.css(offsetParent, 'position') == 'static')) 
                offsetParent = offsetParent.offsetParent;
            return $(offsetParent);
        }
    });
    function num(el, prop){
        return parseInt($.curCSS(el.jquery ? el[0] : el, prop, true)) || 0;
    };
    })(jQuery);
// JavaScript Document
jQuery.fn.absolutize = function()
{
  return this.each(function()
  {
    var element = jQuery(this);
    if (element.css('position') == 'absolute')
    {
      return element;
    }
 
    var offsets = element.offset();
    var top = offsets.top;
    var left = offsets.left;
    var width = element[0].clientWidth;
    var height = element[0].clientHeight;
 
    element._originalLeft = left - parseFloat(element.css("left") || 0);
    element._originalTop = top - parseFloat(element.css("top") || 0);
    element._originalWidth = element.css("width");
    element._originalHeight = element.css("height");
 
    element.css("position", "absolute");
    element.css("top", top + 'px');
    element.css("left", left + 'px');
    element.css("width", width + 'px');
    element.css("height", height + 'px');
    return element;
 
  });
}

/* Added by hCL for Article Level Enhancement CR

$('a.print').click(function() {
	window.print();		
});
*/

$(document).ready(function(){
	Shadowbox.init();
	$('a.print').click(function() {
		self.print();
		return false;
	});	
	
	$('a.recommend').click(function() {
		//insert database call ajax here
		$('a.recommend').replaceWith('<span class="recommend">Recommended (36)</span>'); //simulate update with number					
	});
	/* Commented by hCL for Article Level Enhancement CR*/	
	/*
	$('button[name=PostComment]').click(function() {		
		Shadowbox.open({
			player:     'html',
			title:     	'&nbsp;',
			content:    'http://localhost:8080/preview/www/2.205/1.159?ot=gulfnews.FormPageLayout.ot&commentsform=true',
			animate:	false,
			width:      590,
			height:     530,
			enableKeys:false,
			options: {
				onFinish: function(a) {
					$('#sb-player .postComment').show();					
				},
				enableKeys:false
			}
		});				
	});
	*/

	/*
	$('a.email-a-friend').click(function() {
		Shadowbox.open({
			player:     'html',
			title:     	'&nbsp;',
			content:    '<div class="half">' + $('#emailFriend').html() + '</div>',
			animate:	false,
			width:      590,
			height:     370,
			enableKeys:false,
			options: {
				onFinish: function(a) {
					$('#sb-player #emailFriend').show();
				},
				enableKeys:false
			}
		});
			return false;					
		});*/
	
	$('.shareArticle-links').hide();
	var box = $('<div class="shareArticle-popup"></div>').hide().insertAfter('a.share');
	$('li.share').hover(function() {
		$('.shareArticle-links').clone().appendTo($(this).find('div.shareArticle-popup').html('').append('<a class="closePopup" href="" title="Close Popup">Close Popup</a>').fadeIn()).show();
		$('a.email-a-friend').click(function() {
		Shadowbox.open({
			player:     'html',
			title:     	'&nbsp;',
			content:    '<div class="half">' + $('#emailFriend').html() + '</div>',
			animate:	false,
			width:      590,
			height:     370,
			enableKeys:false,
			options: {
				onFinish: function(a) {
					$('#sb-player #emailAFriend').show();
				},
				enableKeys:false
			}
		});
			return false;					
		});
		$('.shareArticle-popup a.closePopup').click(function() {
			$('div.shareArticle-popup').html('').hide();
			return false;
		});
		return false;
	},function() {
		$('div.shareArticle-popup').html('').hide();
	});
});
