/**
 * Vars
 */

$j = jQuery;
 
/**
 * init on dom ready
 */
$j(document).ready(function() {
  // init carousel
  $j('#eventCalendarSlider').jcarousel({
    scroll: 3,
    animation: 1800
    //easing: 'easeOutBounce'
  });
  
  // init infopanel accordion
  $j(".infoPanelContent").tabs(".infoPanelContent div.infoPanelPane", {tabs: 'a.infoPanelTitel', effect: 'slide', initialIndex: 0});
  
  // primary menu dropdown
  $j('.primaryMenu li').hover(
    function () {
      $j(this).find('a:first').addClass('current');
      $j(this).find('ul').stop(true, true).delay(200).slideDown(1000, 'easeOutBounce');
    }, 
    function () {
       $j(this).find('a:first').removeClass('current');
       $j(this).find('ul').stop(true, true).delay(200).slideUp(500);
    }
  );
  
  // extend searchbar
  $j('#searchBar').hover(
    function () { $(this).stop(true, true).delay(200).animate( { width: '200px' }, 1000 ); }, 
    function () { $(this).stop(true, true).delay(1000).animate( { width: '50px' }, 500 ); }
  );
  
  // login form
  $j('#showLoginForm').click(function() {
    $j(this).toggle();
	$j('#metaBar .login form').animate( { width: '410px' }, 500 );
    $j('ul.loginForm').animate( { width: '510px' }, 500 );
    $j('ul.loginForm input:first').focus();
	if ($j('#sysMsg') != '') $j('#sysMsg').fadeOut(500); $j('#sysMsg').empty();
    return false;
  });
  
  // headlines
  $j('#content h2:first').addClass('first');  /*
  $j('#content h3:first').addClass('first');
  $j('#content h4:first').addClass('first');
  */
  
  // qtranslate link bugfix
  /*
  var hrefs    = $j('#content').find('a');
  var sitename = 'http://shoppingcityseiersberg.dev/';
  var language = $j('html').attr('lang');

  hrefs.each(function() {
  
    theSplit = $j(this).attr('href').split(sitename);
    
    theNewHref = sitename + language + '/' + theSplit[1];
    $j(this).attr('href', theNewHref);
    
  });
*/

  /**
   * subscribe advent contest
   */
   $j('a.subscribeContest').click(function() {
    $j('div.subscribeForm').slideDown();
    return false;
   });

  // init fancybox
  $j(".lightbox").fancybox({
    afterShow  : function() {
                  var src = $j('.fancybox-image').attr('src');
                  console.log(src);
                  $j('.fancybox-inner').append('<div class="share"><iframe src="//www.facebook.com/plugins/like.php?href='+  encodeURIComponent(src) +'&amp;send=false&amp;layout=button_count&amp;width=450&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=21&amp;" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:21px;" allowTransparency="true"></iframe></div>');
                },
    helpers: {
        title : {
        type : 'image'
      }
    }
  });

   
});

