﻿$(document).ready(function()
{
    // adjust styling for macosx-based browsers - remove and append from the backend instead
    if (navigator.appVersion.indexOf('Mac') != -1 || $.browser.safari) {
        $('head').append('<link type="text/css" rel="stylesheet" media="all" href="a/css/webkit.css" />');
    }
    
    // normalize medium weight fonts in IE
    if (navigator.appVersion.indexOf('MSIE') != -1) {
        $('*').css('font-weight', function(i, val) {
            if (parseFloat(val) == 600) return 400;
        });
    }

     if (typeof jQuery.fn.dialog == 'function')
    {
        $('input:text, textarea').toggleVal();
        
        // enable dialog
        $('a.open-newsletter').click(function() {
        	var relId = $(this).attr('id');
            $('#newsletter-details-'+relId).dialog('open');
            return false;
        }),
        
        // dialog customization and form functions
        $('.newsletter-details').dialog({
            autoOpen: false,
            minWidth: 647,
            minHeight: 534,
            position: 'center',
            open: function(e, ui) {
                // add overlay
                $('#page').before('<div id="ui-dialog-overlay"></div>');
                // fix focus bug: http://bugs.jqueryui.com/ticket/4731
                $('.ui-dialog-content :tabbable:first').blur();
                // safari alignment fix
                if ($.browser.safari) {
                    $('.ui-dialog').css('left', '25% !important');
                }
            },
            close: function(e, ui) {
                $('#ui-dialog-overlay').remove();
            }
        }).find('.addmore a').click(function () {
            var dup = $(this).parents('form').find('.spares .textwrapper').clone();
            $(this).parent().before(dup);
            $(this).parents('.container').find('input').toggleVal();
            return false;
        }).find('p.close a').click(function () {
            $(this).dialog('close');
            return false;
        });
    
    
    
     	// enable dialog
        $('a.share_email').click(function() {
            $('#share-email').dialog('open');
            return false;
        });
        
        // dialog customization and form functions
        $('#share-email').dialog({
            autoOpen: false,
            minWidth: 598,
            minHeight: 534,
            position: 'center',
            open: function(e, ui) {
                // add overlay
                $('#page').before('<div id="ui-dialog-overlay"></div>');
                // fix focus bug: http://bugs.jqueryui.com/ticket/4731
                $('.ui-dialog-content :tabbable:first').blur();
                // safari alignment fix
                if ($.browser.safari) {
                    $('.ui-dialog').css('left', '25% !important');
                }
            },
            close: function(e, ui) {
                $('#ui-dialog-overlay').remove();
            }
        }).find('.addmore a').click(function () {
            var dup = $(this).parents('form').find('.spares .textwrapper').clone();
            $(this).parent().before(dup);
            $(this).parents('.container').find('input').toggleVal();
            return false;
        }).find('p.close a').click(function () {
            $('#share-email').dialog('close');
            return false;
        });
    }

    // onrollover button for form submit image buttons - toggle "ovr" to the filename
    $(".buttonwrapper input").hover(
        function () {
            $(this).attr('src', function() {
                return this.src.replace('.png', '_ovr.png');
            });
        },
        function () {
            $(this).attr('src', function() {
                return this.src.replace('_ovr', '');
            });
        }
    );
    
    // onrollover for anchor links with an arrow image - toggle "ovr" to the image filename
    // the img tag requires a "more" class
    $("a").hover(
        function() {
            $(this).find('img.more').attr('src', function() {
                if (!this.src.match('_ovr')) {
                    return this.src.replace('.png', '_ovr.png');
                }
            });
        },
        function() {
            $(this).find('img.more').attr('src', function() {
                return this.src.replace('_ovr', '');
            });
        }
    );
    
    // Client logos - onrollover for anchor links with an arrow image - toggle "ovr" to the image filename
    // the img tag requires a "more" class
    $("a").hover(
        function() {
            $(this).find('img.clients-more').attr('src', function() {
                if (!this.src.match('_ovr')) {
                    var newSrc = this.src.replace('/thumb/', '/thumbover/');
                    newSrc = newSrc.replace('.png', '_ovr.png');                    
                    return newSrc;
                }
            });
        },
        function() {
            $(this).find('img.clients-more').attr('src', function() {
                var newSrc = this.src.replace('/thumbover/', '/thumb/');
                newSrc = newSrc.replace('_ovr', '');
                return newSrc;
			});
        }
    );
    
    // toggle block display
    $('#letstalk a.openblock').click(function() {
        $(this).hide();
        $('#letstalk .toggleblock').slideDown('slow');
    });
    $('#letstalk a.closeblock').click(function() {
        $('#letstalk .toggleblock').slideUp('fast', function() {
            $('#letstalk a.openblock').show();
        });
    });
    
});

function openEmail(link, title)
{
	
};

