﻿/// <reference path="../jquery-1.3.2-vsdoc2.js" />
var adImages;
var editDialog, deleteDialog, tipDialog, mailDialog, reminderDialog, youtubeDialog;

var addthis_config = { services_compact: 'facebook,twitter,favorites,email,more' };

$(function() {
    adImages = new Gallery('adImages', function(image) {
        lightbox.show(image.index);
    });

    var images = [];
    jQuery.each(adImages.images, function() { images.push(this.mega || this.normal); });

    lightbox.setup($('#lightBg'), $('#lightContainer'), images);
    $('#lightImage').click(function(ev) { lightbox.close(); });
    $('#lightContainer .close')
        .unbind('click')
        .click(function(ev) { lightbox.close(); }); // Hax

    editDialog = new Dialog('editDialog');
    deleteDialog = new Dialog('deleteDialog');
    tipDialog = new Dialog('tipDialog');
    mailDialog = new Dialog('mailDialog', function(el) {
        $('#mailBody').show();
        $('#mailDone').hide();
        $('#Contact_Message').val('');
    });
    reminderDialog = new Dialog('reminderDialog');
    youtubeDialog = new Dialog('youtubeDialog', null, function() { $('#ytVideo').html(''); });

    $('.editAdLink').click(function(ev) { editDialog.show(); });
    $('.deleteAdLink').click(function(ev) { deleteDialog.show(); });
    $('.tipLink').click(function(ev) { tipDialog.show(); });
    $('.contactLink').click(function(ev) { mailDialog.show(); });
    $('.reminderLink').click(function(ev) {
        deleteDialog.hide();
        editDialog.hide();
        reminderDialog.show();
    });

    $('#newTipLink').click(function(ev) {
        $('#tipBody').show();
        $('#tipDone').hide();
        $('#Tip_RecipientEmail').val('');
        $('#Tip_Message').val('');
    });

    $('#closeMailLink').click(function(ev) { mailDialog.hide(); });

    $('#deleteForm').submit(function(ev) {
        if ($('#pwdDelete').val().length > 0 && confirm('Är du säker på att du vill ta bort annonsen?'))
            return true;
        return false;
    });

    $('a.youtube').click(function(ev) {
        $('#ytVideo').html(
		            '<object id="ytPlayerObj" style="height: 344px; width: 425px">' +
                    '<param name="movie" value="http://www.youtube.com/v/' + $(this).attr('ytid') + '?autoplay=1&color1=0xb1b1b1&color2=0xcfcfcf&fs=1&feature=player_embedded">' +
                    '<param name="allowFullScreen" value="true">' +
                    '<embed id="ytPlayerEmb" src="http://www.youtube.com/v/' + $(this).attr('ytid') + '?&autoplay=1&color1=0xb1b1b1&color2=0xcfcfcf&fs=1&feature=player_embedded" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="425" height="344">' +
                    '</object>'
                );
        youtubeDialog.show();
    });

});

function dialogDone(dialogName, data) {            
    if (!data.validation || data.validation.isValid) {
        $('#' + dialogName + 'Body').hide();                 
        $('#' + dialogName + 'Done').show();                 
    }
}  
    
