/*

	jQuery Scroller plugin
	Copyright (c) 2010 Max Vergelli

	For support and tutorials visit
	http://maxvergelli.wordpress.com/

	License: GNU Lesser General Public License (LGPL) 
	at http://opensource.org/licenses/lgpl-2.1.php

	This plugin is free software;  you can redistribute it  and/or  modify  it 
	under the terms of the GNU Lesser General Public License as  published  by 
	the Free Software Foundation;  either version 2.1 of the License,  or  (at 
	your option) any later version.
	This software is distributed in the hope  that  it  will  be  useful,  but 
	WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
	or FITNESS FOR A PARTICULAR PURPOSE.  See the  GNU Lesser  General  Public 
	License for more details.
	You should have received a copy of  the  GNU Lesser General Public License 
	along with this library;  if not,  write to the  Free Software Foundation, 
	Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

	THIS COMMENT AND COPYRIGHT NOTICE MUST BE RETAINED IN THE CODE AS IS FOR LEGAL USE

*/
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(6($){$.N.1k=6(){5.8().9();5.8().r(\'7\',[\'R\'])};$.N.1l=6(){5.8().9()};$.N.1m=6(a){5.8().9();5.8().V(\'7\');a=$.W(5.X(),a);5.Y(a)};$.N.1n=6(){5.8().9();5.8().w({s:0,t:0});5.8().V(\'7\')};$.N.Y=6(h){4 x={y:5};h=$.W({S:Z,10:\'11\',12:\'B\',P:\'1o\',13:\'T\',14:\'1p\',15:\'O\',16:\'O\',U:\'1q\'},h);4 i=z h.S==\'17\'?3(h.S):Z;4 j=h.10.E();4 k=h.12.E();4 l=z h.P==\'17\'&&h.P>0?3(h.P):-1;4 m=h.13.E();4 n=h.14.E();4 o=h.15.E();4 p=h.16.E();4 q=h.U.E();x.y.X(h);18();6 18(){x.y.w(\'U\',q);2(j==\'11\'){2(k!=\'B\'&&k!=\'t\'){k=\'B\'};19()}u{2(k!=\'F\'&&k!=\'s\'){k=\'F\'};1a()};2(n==\'O\'){x.y.1b(6(){$(5).8().9();$(5).8().r(\'7\',[\'R\'])})}u{x.y.1b(6(){$(5).8().9()})};2(o==\'O\'){x.y.1c(6(){$(5).8().9();$(5).8().r(\'7\',[\'R\'])})}u{x.y.1c(6(){$(5).8().9()})};2(p!=\'O\'){x.y.8().9()}};6 1a(){x.y.8().1d(\'7\',6(a,c){4 b=$(5);4 d=3(b.G().H());4 e=3(b.H());4 f=3(b.A().s);4 v=i>0&&i<C?(C-i)*C:1e;4 g=3(v*e/C)+v;2(m==\'Q\'){I(k){J\'F\':2(z c==\'D\'){b.w({s:d-e})};d=f-(e+d);K;L:2(z c==\'D\'){b.w({s:0})};d+=f+e}}u{I(k){J\'F\':2(z c==\'D\'){b.w({s:d});d=-e}u{d=f-(e+d)};K;L:2(z c==\'D\'){b.w({s:-e})}u{d+=f+e}}};2(l<0||l>0){2(l>0){l--};b.1f({s:d},{1g:g,1h:\'T\',1i:6(){b.r(\'7\')},1j:6(){I(m){J\'Q\':2(k==\'F\'){2(3(b.A().s)<=0){k=\'s\';b.9();b.r(\'7\')}}u{2(3(b.A().s)+3(b.H())>=3(b.G().H())){k=\'F\';b.9();b.r(\'7\')}};K;L:2(k==\'F\'){2(3(b.A().s)<-3(b.H())){b.9();b.r(\'7\')}}u{2(3(b.A().s)>3(b.G().H())){b.9();b.r(\'7\')}}}}})}}).r(\'7\')};6 19(){x.y.8().1d(\'7\',6(a,c){4 b=$(5);4 d=3(b.G().M());4 e=3(b.M());4 f=3(b.A().t);4 v=i>0&&i<C?(C-i)*C:1e;4 g=3(v*e/C)+v;2(m==\'Q\'){I(k){J\'B\':2(z c==\'D\'){b.w({t:d-e})};d=f-(e+d);K;L:2(z c==\'D\'){b.w({t:0})};d+=f+e}}u{I(k){J\'B\':2(z c==\'D\'){b.w({t:d});d=-e}u{d=f-(e+d)};K;L:2(z c==\'D\'){b.w({t:-e})}u{d+=f+e}}};2(l<0||l>0){2(l>0){l--};b.1f({t:d},{1g:g,1h:\'T\',1i:6(){b.r(\'7\')},1j:6(){I(m){J\'Q\':2(k==\'B\'){2(3(b.A().t)<=0){k=\'t\';b.9();b.r(\'7\')}}u{2(3(b.A().t)+3(b.M())>=3(b.G().M())){k=\'B\';b.9();b.r(\'7\')}};K;L:2(k==\'B\'){2(3(b.A().t)<-3(b.M())){b.9();b.r(\'7\')}}u{2(3(b.A().t)>3(b.G().M())){b.9();b.r(\'7\')}}}}})}}).r(\'7\')};1r 5}})(1s);',62,91,'||if|parseInt|var|this|function|marquee|children|stop||||||||||||||||||trigger|top|left|else||css|_|me|typeof|position|right|100|undefined|toLowerCase|bottom|parent|height|switch|case|break|default|width|fn|play|loop|pingpong|resume|velocity|linear|cursor|unbind|extend|data|SetScroller|50|direction|horizontal|startfrom|movetype|onmouseover|onmouseout|onstartup|number|main|scrollHorizontal|scrollVertical|mouseover|mouseout|bind|5000|animate|duration|easing|complete|step|PlayScroller|PauseScroller|ResetScroller|RemoveScroller|infinite|pause|pointer|return|jQuery'.split('|'),0,{}))
/**
 * Name: Scripts.js
 * Date: February 2011
 * Description:
 * Version: 1.0
 * Coder: Enrique Ramirez
 * Coder URI: http://enrique-ramirez.com
*/

$.fn.infiniteCarousel = function () {

    function repeat(str, num) {
        return new Array( num + 1 ).join( str );
    }
  
    return this.each(function () {
        var $wrapper = $('> div', this).css('overflow', 'hidden'),
            $slider = $wrapper.find('> ul'),
            $items = $slider.find('> li'),
            $single = $items.filter(':first'),
            
            singleWidth = $single.outerWidth(), 
            visible = Math.ceil($wrapper.innerWidth() / singleWidth),
            currentPage = 1,
            pages = Math.ceil($items.length / visible);            


        // 1. Pad so that 'visible' number will always be seen, otherwise create empty items
        if (($items.length % visible) != 0) {
            $slider.append(repeat('<li class="empty" />', visible - ($items.length % visible)));
            $items = $slider.find('> li');
        }

        // 2. Top and tail the list with 'visible' number of items, top has the last section, and tail has the first
        $items.filter(':first').before($items.slice(- visible).clone().addClass('cloned'));
        $items.filter(':last').after($items.slice(0, visible).clone().addClass('cloned'));
        $items = $slider.find('> li'); // reselect
        $items.addClass('item');
        // 3. Set the left position to the first 'real' item
        $wrapper.scrollLeft(singleWidth * visible);
        
        // 4. paging function
        function gotoPage(page) {
            var dir = page < currentPage ? -1 : 1,
                n = Math.abs(currentPage - page),
                left = singleWidth * dir * visible * n;
            
            $wrapper.filter(':not(:animated)').animate({
                scrollLeft : '+=' + left
            }, 500, function () {
                if (page == 0) {
                    $wrapper.scrollLeft(singleWidth * visible * pages);
                    page = pages;
                } else if (page > pages) {
                    $wrapper.scrollLeft(singleWidth * visible);
                    // reset back to start position
                    page = 1;
                } 

                currentPage = page;
            });
        }
        
        $wrapper.after('<a class="arrow-left"></a><a class="arrow-right"></a>');
        
        // 5. Bind to the forward and back buttons
        $('.arrow-left', this).click(function () {
            return gotoPage(currentPage - 1);
        });
        
        $('.arrow-right', this).click(function () {
            return gotoPage(currentPage + 1);
        });
        
        // create a public interface to move to a specific page
        $(this).bind('goto', function (event, page) {
            gotoPage(page);
        });
        
        // Calculate number of bullet points
  		var totalElements = $("#slides-container ul li[class='item']").length;
  		var bullet_needle = Math.ceil(totalElements/3);
  		var i = 1;
    });  
};

jQuery.fn.liScroll = function(settings) {
		settings = jQuery.extend({
		travelocity: 0.07
		}, settings);		
		return this.each(function(){
				var $strip = jQuery(this);
				$strip.addClass("newsticker")
				var stripWidth = 0;
				var $mask = $strip.wrap("<div class='mask'></div>");
				var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");								
				var containerWidth = $strip.parent().parent().width();	//a.k.a. 'mask' width 	
				$strip.find("li").each(function(i){
				stripWidth += jQuery(this, i).outerWidth(true); // thanks to Michael Haszprunar
				});
				$strip.width(stripWidth);			
				var totalTravel = stripWidth+containerWidth;
				var defTiming = totalTravel/settings.travelocity;	// thanks to Scott Waye		
				function scrollnews(spazio, tempo){
				$strip.animate({left: '-='+ spazio}, tempo, "linear", function(){$strip.css("left", containerWidth); scrollnews(totalTravel, defTiming);});
				}
				scrollnews(totalTravel, defTiming);				
				$strip.hover(function(){
				jQuery(this).stop();
				},
				function(){
				var offset = jQuery(this).offset();
				var residualSpace = offset.left + stripWidth;
				var residualTime = residualSpace/settings.travelocity;
				scrollnews(residualSpace, residualTime);
				});			
		});	
};

$(document).ready(function () {
	$('#slides-container').infiniteCarousel();
	
	$('.text').each(function() {
		var default_value = this.value;
		$(this).focus(function() {
			if(this.value == default_value) {
				this.value = '';
			}
		});
		$(this).blur(function() {
			if(this.value == '') {
				this.value = default_value;
			}
		});
	});
	
	$('#switch').click(function() {
		$('#stylesheet').attr('href','http://www.celldrinks.co.uk/wp-content/themes/cell-drinks/css/text-only.css')
	});

	//$("ul#ticker").liScroll();

	//create ticker
	$('#ticker').wrap('<div id="tscroller" />') ;
	$('#tscroller').SetScroller({	velocity: 	 85,
											direction: 	 'horizontal',
											startfrom: 	 'right',
											loop:		 'infinite',
											movetype: 	 'linear',
											onmouseover: 'pause',
											onmouseout:  'play',
											onstartup: 	 'play',
											cursor: 	 'pointer'
										});

	
	 $("#login").fancybox({
		'centerOnScroll' : true,
		'modal' : true,
		'overlayColor' : "#000",
		'overlayOpacity': ".8",
		'padding' : 0,
		'transitionIn' : 'elastic',
		'transitionOut'	: 'elastic'
	});
	
	$("#login").click();
});

function verify_age()
{
	var day = $('#verify-form select[name=dayv]').val();
	var month = $('#verify-form select[name=monthv]').val();
	var year = $('#verify-form select[name=yearv]').val();
	var Birth = new Date(parseInt(year),parseInt(month)-1,parseInt(day));
	var Now = new Date();
	var diff =  Math.floor((( Now - Birth ) / 86400000)/365);
	if(diff>=18)
		return true ;
	else
	{
		// $('#verify-form .verification-failed').show() ;
		self.location="http://www.drinkaware.co.uk/about-us/information-for-under-18s";	
		return false ;	 	
        }
}
