(function($) {
  $.fn.blink = function(options) {
    var defaults = { delay:500 };
    var options = $.extend(defaults, options);

    return this.each(function() {
      var obj = $(this);

      setInterval(function() {
        if ($(obj).css("visibility") == "visible") {
          $(obj).css('visibility', 'hidden');
        } else {
          $(obj).css('visibility', 'visible');
        }
      }, options.delay);
    });
  }
}(jQuery));

$(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-', '');

        var base_image = '/wp-content/themes/liaisons/images/coming-soon-lrg.jpg?201101';

        //camera shy base image
        if ($(this).hasClass('camera_shy')) {
          base_image = '/wp-content/themes/liaisons/images/camera_shy_296x293.jpg?201101';
        }

        //NAME
        $(profile).find('span.name').text(name);
        $(profile).find('p.link').not('.share').find('a').text('To see '+name).attr('href', '/contact-liaisons-sydney-brothel?l='+name);
        $(profile).find('p.share').find('a').attr('href', '/share-with-friend?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());

        //HAIR
        $(profile).find('span.hair').text($(this).find('span.hair').text());

        //HEIGHT
        $(profile).find('span.height').text($(this).find('span.height').text());

        //SIZE
        $(profile).find('span.size').text($(this).find('span.size').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', base_image);
            $(this).parent().attr('href', base_image);
        });

        //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;
    });

    //escorts click
    $('div#escorts_list.escorts ul#home_pods li.mini_profile_escort a.thumb').click(function() {
        $(this).parent().find('img:eq(0)').attr('src', $(this).attr('href'));

        return false;
    });

    $('div#escorts_list.escorts ul#home_pods li.mini_profile_escort 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();
        }
    }

    if ($('.ladies ul.girls li').length != 0) {
      //Pre select using hash if available
      if (window.location.hash != '') {
        $('.ladies ul.girls li span.name:contains("'+window.location.hash.replace('#', '')+'")').each(function() {
          if ($(this).text() == window.location.hash.replace('#', '')) {
            $(this).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;
    });

    $('#ladies_new_toggle').click(function() {
      $('ul.girls, ul.escort_girls_list').toggleClass('new_active_toggle');
      $(this).toggleClass('active');
    });

    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');
        }
    });

    //home hero  
    /*if ($('#hero_girl').length == 1) {
      var herogirl = $('#hero_girl');
      var cyclecount = 2;
      var cyclecurrent = 1;

      $.timer(6000, function (timer) {
        herogirl.animate({opacity: 0}, 1000, function() {
          $(this).css('backgroundImage', $(this).css('backgroundImage').replace('hero'+cyclecurrent, 'hero'+cyclecount)).animate({opacity: 1}, 1000);
          cyclecount  += 1;
          cyclecurrent = cyclecount - 1;
          if (cyclecount > 7) {
            cyclecount = 1;
          }
        });
      });
    }*/

    $('#youtube_clip a, #home_pods #video_promo a').click(function() {
      $.fancybox({'padding':0, 'autoScale':false, 'transitionIn':'none', 'transitionOut':'none', 'title':this.title, 'width':680, 'height':495, 'href':this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'), 'type':'swf', 'swf':{'wmode':'transparent', 'allowfullscreen':'true'}});

      return false;
    });

    $('#lticker #lticker01 li span').blink();

    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 ladies 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";
    });
});
