var article = 0;
var ajaxloaddelay = 0;
var ajaxloads = new Array();
var like_status = 0;

$(document).ready(function() {
    Cufon.replace('.bubble');
});

if(hs) {
hs.graphicsDir = '/js/highslide/highslide/graphics/';
hs.align = 'center';
hs.transitions = ['expand','crossfade'];
hs.outlineType = 'rounded-white';
hs.fadeInOut = false;
hs.showCredits = false;
hs.dimmingOpacity = 0.7;
}

$(document).ready(function() {
});

$(window).load(function() {
    if($('#a1').length && $('#a1').html().indexOf('No matching campaign') != -1) {
	$('#a1').remove();
    }
});

function closeTopDrop() {
    $('#topdrop').animate({ 'height': 0 }, 300);
    $.get(window.location.href,'closetopdrop=1');
}

function galleryPop(obj) {
    if(false && !like_status && article) {
	alert("Du skal 'Synes godt om' os på Facebook for at se billederne!\n\nTryk på 'Synes godt om' knappen først!");
	return false;
    }
    $('iframe, object, embed').addClass('galleryPopHide').css('visibility','hidden');
    $('html').css('overflow','hidden').scroll(function() {
	return false;
    });
    $('#galleryPop, #galleryPopMask').remove();

    $('body').append('<div id="galleryPopMask"></div>');
    $('body').append('<div id="galleryPop"><img class="close" src="/graphics/gallerypop_close.png" alt="Luk galleriet" title="Luk galleriet"/></div>');

    $('#galleryPop').css({ 'background-color': '#ffffff', 'padding': '20px 0 20px 0', 'display': 'block', 'position': 'fixed', 'z-index': 10001, 'height': ($(window).height()-80), 'width': 970, 'top': 20, 'left': (($(window).width()-970)/2), 'border-radius': 3, 'overflow': 'hidden' });
    $('#galleryPopMask').css({ 'background-color': '#000000', 'display': 'block', 'position': 'fixed', 'top': 0, 'left': 0, 'width': $(window).width(), 'height': $(window).height(), 'opacity': 0, 'z-index': 10000 });
    $('#galleryPop img.close').css({ 'position': 'absolute', 'top': 3, 'right': 3, 'cursor': 'pointer' });

    $('#galleryPopMask').animate({ 'opacity': 0.8 }, 0, function() {
	$('#galleryPop').append('<iframe id="galleryPopIframe" src="'+$(obj).attr('href')+'" style="width: 970px; height: '+($(window).height()-80)+'px; position: absolute; top: 20px; left: 0; display: block;" width="970" frameborder="0"></iframe>');
	$('#galleryPopIframe').focus().css('width', 970);
    });

    $('#galleryPopMask, #galleryPop img.close, #goarticle').click(function() {
	galleryPopClose();
    });
    return false;
}

function galleryPopClose() {
    $('html').css('overflow','scroll').scroll(function() {
        return true;
    });
    $('#galleryPop').animate({ 'opacity': 0 }, 0, function() {
	$('#galleryPopMask').animate({ 'opacity': 0 }, 0, function() {
	    $('#galleryPop, #galleryPopMask').remove();
    	    $('.galleryPopHide').removeClass('galleryPopHide').css('visibility','visible');
        });
    });
}

$(document).ready(function() {
    $('.post img').each(function() {
	var s = $(this).attr('src');
	if(s.indexOf('connery.dk/') == -1 && s.indexOf('aniston.dk/') == -1 && s.indexOf('motorsektionen.dk/') == -1 && s.indexOf('modesektionen.dk/') == -1) {
	    $(this).addClass('external');
	}
    });
    
    $('#maincol .frontarticles a:odd').css('margin-right','0');
    $('#maincol .frontarticles a:even').css('clear','left');
    $('#newestusers a:last, .latestlogins a:last').css('margin-right','0');
    $('#vsfp.category a:odd').css('margin-right','0');
    $('#category.frontarticles a:nth-child(3n)').css('margin-right','0');
    $('#category.frontarticles a:nth-child(3n+1)').css('clear','left');
    
/*
    $('a').each(function() {
	if($(this).attr('href') && $(this).attr('href').indexOf('http://') != -1) {
	    $(this).click(function() {
		    if(window.location.href.indexOf('connery.dk') != -1) {
			var pageTracker=_gat._getTracker("UA-302130-1");
		    }
		    else if(window.location.href.indexOf('aniston.dk') != -1) {
			var pageTracker=_gat._getTracker("UA-302130-2");
		    }
		    else if(window.location.href.indexOf('motorsektionen.dk') != -1) {
			var pageTracker=_gat._getTracker("UA-6396967-3");
		    }
		    else if(window.location.href.indexOf('modesektionen.dk') != -1) {
			var pageTracker=_gat._getTracker("UA-6396967-3");
		    }
		    var lp = $(this).attr('href').replace('https://','').replace('http://','').replace('www.','').split('.');
		    pageTracker._trackEvent('Outbound links', lp[0]);
		    var gt = $(this).attr('href');
		    var target = $(this).attr('target');
		    setTimeout(function() {
			if(target == '_blank') {
			    window.open(gt);
			}
			else {
			    document.location = gt;
			}
		    }, 500);
		return false;
	    });
	}
    });
*/
});

if (typeof $.cookie == 'undefined') {

        /**

         * Cookie plugin

         *

         * Copyright (c) 2006 Klaus Hartl (stilbuero.de)

         * Dual licensed under the MIT and GPL licenses:

         * http://www.opensource.org/licenses/mit-license.php

         * http://www.gnu.org/licenses/gpl.html

         *

         */



        /**

         * Create a cookie with the given name and value and other optional parameters.

         *

         * @example $.cookie('the_cookie', 'the_value');

         * @desc Set the value of a cookie.

         * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: '$.com', secure: true });

         * @desc Create a cookie with all available options.

         * @example $.cookie('the_cookie', 'the_value');

         * @desc Create a session cookie.

         * @example $.cookie('the_cookie', null);

         * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain

         *       used when the cookie was set.

         *

         * @param String name The name of the cookie.

         * @param String value The value of the cookie.

         * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.

         * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.

         *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.

         *                             If set to null or omitted, the cookie will be a session cookie and will not be retained

         *                             when the the browser exits.

         * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).

         * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).

         * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will

         *                        require a secure protocol (like HTTPS).

         * @type undefined

         *

         * @name $.cookie

         * @cat Plugins/Cookie

         * @author Klaus Hartl/klaus.hartl@stilbuero.de

         */



        /**

         * Get the value of a cookie with the given name.

         *

         * @example $.cookie('the_cookie');

         * @desc Get the value of a cookie.

         *

         * @param String name The name of the cookie.

         * @return The value of the cookie.

         * @type String

         *

         * @name $.cookie

         * @cat Plugins/Cookie

         * @author Klaus Hartl/klaus.hartl@stilbuero.de

         */

        $.cookie = function(name, value, options) {

            if (typeof value != 'undefined') { // name and value given, set cookie

                options = options || {};

                if (value === null) {

                    value = '';

                    options.expires = -1;

                }

                var expires = '';

                if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {

                    var date;

                    if (typeof options.expires == 'number') {

                        date = new Date();

                        date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));

                    } else {

                        date = options.expires;

                    }

                    expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE

                }

                // CAUTION: Needed to parenthesize options.path and options.domain

                // in the following expressions, otherwise they evaluate to undefined

                // in the packed version for some reason...

                var path = options.path ? '; path=' + (options.path) : '';

                var domain = options.domain ? '; domain=' + (options.domain) : '';

                var secure = options.secure ? '; secure' : '';

                document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');

            } else { // only name given, get cookie

                var cookieValue = null;

                if (document.cookie && document.cookie != '') {

                    var cookies = document.cookie.split(';');

                    for (var i = 0; i < cookies.length; i++) {

                        var cookie = $.trim(cookies[i]);

                        // Does this cookie string begin with the name we want?

                        if (cookie.substring(0, name.length + 1) == (name + '=')) {

                            cookieValue = decodeURIComponent(cookie.substring(name.length + 1));

                            break;

                        }

                    }

                }

                return cookieValue;

            }

        };

     }

	// handles like and unlike events

     function like_gate_handle_event(pars) {
       pars = pars || {};
       if (pars.event == 'unlike') {
            $('.like-gate-result').hide('slow').html('');
            $.cookie('like_gate', null, { path: '/' });
            like_status = 0;
            return true;
       }

       $.cookie('like_gate', 1, { expires: 365, path: '/' }); 
	like_status = 1;
	$('iframe').each(function() {
	    if($(this).attr('src').indexOf('comment_widget_shell') != -1) {
		$(this).remove();
	    }
	});
       $('.like-gate-result').html($('.like-gate-secret').html()).show('slow');

     }


