$(document).ready(function() {
    $('.jclock').jclock();

    $('ul.girls li').click(function() {
        var profile = $('#mini_profile');
        var name    = $(this).find('span.name').text();
        var girl_id = $(this).closest('li').attr('id').replace('lg-', '');

        //NAME
        $(profile).find('span.name').text(name);
        $(profile).find('p.link a').text('To see '+name).attr('href', '/contact-liaisons-sydney-brothel?l='+name);
        $(profile).find('img').attr('alt', name);

        //AGE
        $(profile).find('span.age').text($(this).find('span.age').text());

        //BUST
        $(profile).find('span.bust').text($(this).find('span.bust').text());

        //DESC
        $(profile).find('p.desc').text($(this).find('p.desc').text());

        //Set base coming soon image as default
        $(profile).find('img').each(function() {
            $(this).attr('src', '/wp-content/themes/liaisons/images/coming-soon-lrg.jpg');
            $(this).parent().attr('href', '/wp-content/themes/liaisons/images/coming-soon-lrg.jpg');
        });

        //JSON request for the images for that particular girl
        $.getJSON("/wp-content/themes/liaisons/_get_images.php", {girl_id:girl_id}, function(data) {
            $.each(data, function(indx, image) {
                if (indx == 0) {
                    $(profile).find('img:eq(0)').attr('src', image);
                    $(profile).find('p.main_pic a:eq(0)').attr('href', image);
                }
                $(profile).find('img:eq('+(indx+1)+')').attr('src', image.replace('.jpg', '-90x90.jpg'));
                $(profile).find('p.main_pic a:eq('+(indx+1)+')').attr('href', image);
            });
        });

        return false;
    });

    $('#mini_profile p.main_pic a.thumb').click(function() {
        $('#mini_profile p.main_pic img:eq(0)').attr('src', $(this).attr('href'));

        return false;
    });

    $('#mini_profile p.main_pic a:eq(0)').click(function() {
        return false;
    });

    if ($('.roster ul.girls li').length != 0) {
        //Pre select using hash if available
        if (window.location.hash != '') {
            $('.roster ul.girls li span.name:contains("'+window.location.hash.replace('#', '')+'")').each(function() {
                if ($(this).text() == window.location.hash.replace('#', '')) {
                    $(this).click();
                }
            });
        } else {
            $('.roster ul.girls li:first').click();
        }
    }

    $('#tour_gallery li').click(function() {
        $(this).parent().find('li').removeClass('selected');
        $('#main_pic img').attr('src', $(this).find('a').attr('href'));
        $(this).addClass('selected');

        return false;
    });

    if ($('#map').length) {
        $('#map').html('<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com.au/maps?q=535+Glenmore+Road+Edgecliff,+NSW+2027&amp;oe=utf-8&amp;client=firefox-a&amp;ie=UTF8&amp;split=0&amp;gl=au&amp;ei=8hnPSaqoGIvCsQP1kdT8Dw&amp;ll=-33.873729,151.235132&amp;spn=0.012471,0.018239&amp;z=15&amp;iwloc=addr&amp;output=embed"></iframe>');
    }

    $('#subscribe_email').focus(function() {
        if ($(this).val() == 'Enter your email address') {
            $(this).val('');
        }
    });

    $('#subscribe_email').blur(function() {
        if ($(this).val() == '') {
            $(this).val('Enter your email address');
        }
    });

    if (!$.cookie('disclaimer')) {
        $('#page').css('position', 'relative');
        $('#page').append('<div id="disclaimer"><p>WARNING: To access this site you must read the following certification:</p><p class="warning">I am at least 18 years of age. I understand prostitution services in licensed premises is legal in the state of <abbr title="New South Wales">NSW</abbr> to persons over the age of 18 years. I believe the material contained in this adult website is not offensive in any manner or form. All models on this site are over 18 and are the actual service providers at Liaisons.</p><p><a href="#" id="enter">Click here to confirm you are 18 years or older</a><br />&nbsp;<br /><a href="#" id="leave">Leave now</a></p></div>');
    }

    $('#enter').click(function() {
        //Set cookie
        $.cookie('disclaimer', '1');
        $('#disclaimer').hide();

        return false
    });

    $('#leave').click(function() {
        window.location = "http://www.google.com";
    });
});