/*
 * ELG Website Custom Javascript
 * Code by J.Patchett at Tastic Multimedia for Simpson Direct for European Lottery Guild
 */

//Language drop down replacement
jQuery(document).ready(function(){
  jQuery('#language2 select').combobox(
        {comboboxContainerClass: "comboboxContainer",
         comboboxValueContainerClass: "comboboxValueContainer",
         comboboxValueContentClass: "comboboxValueContent",
         comboboxDropDownClass: "comboboxDropDownContainer",
         comboboxDropDownButtonClass: "comboboxDropDownButton",
         comboboxDropDownItemClass: "comboboxItem",
         comboboxDropDownItemHoverClass: "comboboxItemHover",
         comboboxDropDownGroupItemHeaderClass: "comboboxGroupItemHeader",
         comboboxDropDownGroupItemContainerClass: "comboboxGroupItemContainer",
         animationType: "slide", width: "145px", height:"24px" });
      jQuery('#language input').hide();
  });
jQuery('#language select').change(function(){
  jQuery('#language').submit();
});

    jQuery('.read-more-off').click(function(){
      if(jQuery(this).hasClass('read-more-on')){
        jQuery(this).parent().find('.news-full').slideUp(function(){jQuery(this).html('')});
        jQuery(this).removeClass('read-more-on').css('background','url(/assets/images/news2/readmore_off.gif) no-repeat 3px 50%').text(elglang.l_02_read_more);
      }else{
        jQuery(this).addClass('read-more-on');
        jQuery(this).css('background','url(/assets/images/news2/ajax-loader.gif) no-repeat 0px 50%').text(elglang.l_01_loading_story);
        jQuery(this).parent().find('.news-full').hide();
        jQuery(this).parent().find('.news-full').load(jQuery(this).attr('href')+' #news-story .news-story-detail div#story-full','',function(){
          jQuery(this).slideDown();
          jQuery(this).parent().find('.read-more-off').css('background','url(/assets/images/news2/readmore_on.gif) no-repeat 3px 0px').text(elglang.l_03_hide_story);
        });
      }
      return false;
    });


jQuery('#results-date-chooser input').hide();
jQuery('#results-date-chooser select').change(function(){
  jQuery('#results-date-chooser').submit();
  jQuery('#results-listing, .results-info > div:not(.hr)').slideUp(function(){
    jQuery('#results-listing, .results-info > div:not(.hr)').html(elglang.l_11_loading_results);
    jQuery('#results-listing, .results-info > div:not(.hr)').slideDown();

  });
})

jQuery('#results-listing a').click(function(){
  jQuery('#results-listing').slideUp(function(){
    jQuery('#results-listing').html(elglang.l_11_loading_results);
    jQuery('#results-listing').slideDown();

  });
})

//Validate 18 years
jQuery('form[name="form"]').submit(function(){
  alert('checking');


});

/*
jQuery('#lotto-map li').each(function(){
	jQuery(this)[0].tick_down=new tick_down(jQuery(this));
	var self=jQuery(this)[0];
	setTimeout(function(){self.tick_down.tick()},1000);
})
*/
function tick_down(target){
	this.tgt=target;
	this.tgt.find('span.cd-s').append('<span class="nbr2">-</span>');
	this.current_span='nbr';
	this.next_span='nbr2';
	this.tgt.find('span.cd-s span.nbr2').css('opacity',0);

	this.tick=function(){
		var cufon_on=(this.tgt.find('.cufon').length>0);
		//Get seconds
		var seconds_box=this.tgt.find('.cd-s span.'+this.current_span);
		var next_seconds_box=this.tgt.find('.cd-s span.'+this.next_span);
		var seconds=(cufon_on)?this.tgt.find('.cd-s > .cufon > .cufon-alt').text():seconds_box.text();
		new_seconds=seconds-1;

		//Get Mins
		var mins_box=this.tgt.find('.cd-m span.nbr');
		var mins=(cufon_on)?this.tgt.find('.cd-m > .cufon > .cufon-alt').text():mins_box.text();
		if(new_seconds<0){
			new_seconds=59;
			new_mins=mins-1;
		}else{
			new_mins=mins;
		}

		//Get Hours
		var hours_box=this.tgt.find('.cd-h span:not(".lbl")');
		var hours=(cufon_on)?this.tgt.find('.cd-h > .cufon > .cufon-alt').text():hours_box.text();
		if(new_mins<0){
			new_mins=59;
			new_hours=hours-1;
		}else{
			new_hours=hours;
		}


		var self=this.tgt;
		var seconds_anim=this.tgt.find('span.cd-s span.'+this.current_span);
		var next_seconds_anim=this.tgt.find('span.cd-s span.'+this.next_span);
		//Fade out the current seconds div
		seconds_anim.animate({'marginLeft':'-20px','opacity':0},400);
		//Set the new seconds value on the replacment span and prepare it to be animated
		next_seconds_box.text(new_seconds);
		next_seconds_box.css('marginLeft','20px').css('opacity',0);
		//Animate the new seconds box
		setTimeout(function(){
			next_seconds_anim.animate({'marginLeft':'0px','opacity':1},400);
		},400);
		//Flip the seconds spans for the next run
		var p=this.current_span;
		this.current_span=this.next_span;
		this.next_span=p;

		if(new_mins!=mins){
			this.tgt.find('.cd-m').animate({'marginLeft':'-20px','opacity':0},800,'',function(){
				mins_box.text(new_mins);
				self.find('.cd-m').css('marginLeft','20px');
				self.find('.cd-m').animate({'marginLeft':'0px','opacity':1},800);
			});
		}
		var self=this;
		setTimeout(function(){self.tick()},970);
	}
}