// JavaScript Document
// Set external links to open in a new window
$(function() {
  $('a').each(function() {
    var $link = $(this);
    if (this.rel == 'external' && this.href.indexOf('javascript:') < 0 && this.href.indexOf('mailto:') < 0) {
      this.target = '_blank';
      $link.addClass('external');
    }
  });
});

$(function(){
  $(".modal").colorbox({iframe:true, innerWidth:600, innerHeight:450});
 
  // image galleries for locations.
  $(".imgs a").colorbox({
    maxWidth: '90%',
    maxHeight: '90%'
  });
  $("a.launch-gallery").click(function() {
    $(this).closest('dl').find('dd.imgs a:first').click();
    return false;
  });
  
  // quick relationship value for a generic gallery.
  $("a[rel='gal']").colorbox({
    maxWidth: '90%',
    maxHeight: '90%'
  });
  
  // create the image rotator
  setInterval(rotateImages, 3500);
  
  // flash instances 
  var flashvars = {};
  var params = {wmode:"opaque"};
  var attributes = {};

  if (typeof swfobject != 'undefined') {
	  if ($('#homeflash').length) {
		params = {wmode:"transparent"};
    	swfobject.embedSWF("/swf/8724_brinker_homepage.swf", "homeflash", "960", "404", "9.0.0","/swf/expressInstall.swf", flashvars, params, attributes);
	  }
	  if ($('#world-flash').length) {
	    var flashvars = { xmlFile: "/swf/our-world/images.xml" };
		swfobject.embedSWF("/swf/8724_brinker_our_world.swf", "world-flash", "377", "284", "9.0.0", "/swf/expressInstall.swf", flashvars, params, attributes);
      }
      if ($('#careers-flash').length) {
        var flashvars = { xmlFile: "/swf/our-careers/images.xml" };
        swfobject.embedSWF("/swf/our-careers/8724_brinker_our_careers.swf", "careers-flash", "475", "375", "9.0.0", "/swf/expressInstall.swf", flashvars, params, attributes);
      }
	  if ($('#maggianos-flash').length) {
	    var flashvars = { xmlFile: "/swf/our-restaurants/maggianos/images.xml" };
        swfobject.embedSWF("/swf/our-restaurants/maggianos/8724_brinker_our_restaurants_maggianos.swf", "maggianos-flash", "340", "284", "9.0.0", "/swf/expressInstall.swf", flashvars, params, attributes);
	  }
      if ($('#chilis-flash').length) {
        var flashvars = { xmlFile: "/swf/our-restaurants/chilis/images.xml" };
		swfobject.embedSWF("/swf/our-restaurants/chilis/8724_brinker_our_restaurants_chilis.swf", "chilis-flash", "340", "284", "9.0.0", "/swf/expressInstall.swf", flashvars, params, attributes);
	  }
      if ($('#culture-flash').length) {
        var flashvars = { xmlFile: "/swf/our-culture/images.xml" };
        swfobject.embedSWF("/swf/our-culture/8724_brinker_our_culture.swf", "culture-flash", "522", "352", "9.0.0", "/swf/expressInstall.swf", flashvars, params, attributes);
      }
	  
  }
 
 
});

$(function(){ 
  // news ticker
  $('ul#brinker-news li:not(:first)').hide();
  setInterval(function() {
    if (!$('ul#brinker-news').data('pause')) {
      $('ul#brinker-news li:visible').fadeOut('default', function() {
        var $next = $(this).next('li');
        if (!$next.length) {
          $next = $(this).parent().find('li:first');
        }
        $next.fadeIn('default');
      });
    }
  }, 5000);
  var pause = function() {$(this).data('pause', true);};
  var resume = function() {$(this).data('pause', false);}
  $('ul#brinker-news').hover(pause, resume)
    .focusin(pause)
    .focusout(resume);
});

function rotateImages() {
	var current = $('.fade li.current');
	var next = current.next('li');
	if (next.length == 0) {
		next = $('.fade li:first');
  }

	current.removeClass('current').addClass('previous');
	next.css({ opacity: 0.0 }).addClass('current').animate({ opacity: 1.0 }, 1000,
		function() {
			current.removeClass('previous');
    }
  );
}

