//global variables:

function scrollDIV(x,y,z){this.curUL = x; this.nextUL = y; this.totalUL = z}

var intervalId = new Array(), curScrollDIV = new Array(), rotateObjP = new Array();



var elem, duration=8000;

var intID, intID2;

//var curBox=0, nextBox=0, eachBoxWidth;

jQuery(document).ready(function(){

	

	//Banner play/pause:

	if(jQuery(".scroll_box ul").length > 1){

		//initialize global variables:

		elem='.scroll_box';

		var rotateObj = new Array();

		jQuery('.scroll_cont').each(function(i){

			jQuery(this).find(elem).each(function(index){

				rotateObj[index] = new scrollDIV(0, 1, jQuery(this).find("ul").length);

			});

			rotateObjP[i] = rotateObj;

			rotateObj = new Array();

			curScrollDIV[i] = 0;

			

			//auto play start:

			playBnr(i);

		});

		d = new Detector();

		var f_size = d.test('DINBold');

		//alert(f_size);

		//if(f_size == false) jQuery('ul.main_nav li a').css("padding","13px 16px 0");

	};

	

	

	jQuery('.scroll_link').each(function(i){

		jQuery(this).find('.scroll_butn a').each(function(j){

			jQuery(this).click(function(){

				if(!jQuery(this).hasClass('slctTab')){

					pauseBnr(i);

					

					jQuery(this.parentNode).find('a').removeClass('slctTab').eq(j).addClass('slctTab');

					jQuery('.scroll_cont:eq('+i+') .scroll_box').hide().eq(j).fadeIn().find('ul').css('top','100%').eq(0).css('top','0');

					jQuery('.scroll_txt:eq('+i+') i').hide().eq(j).fadeIn();

					rotateObjP[i][curScrollDIV[i]].curUL=0;

					curScrollDIV[i] = j; //alert(i+' , '+j);

					

					playBnr(i);

				}

			});

		});

	});

	

		

		jQuery("ul.main_nav > li").hover(

			function(){jQuery(this).find('ul').stop(true,true).slideDown(); },

			function(){jQuery(this).find('ul').slideUp(); }

		);

		

		jQuery('.profileList li a').click(

			function(){

			

			if(jQuery(this).next().is(':hidden')){

				jQuery('.profileCont').hide();

				jQuery(this).next().slideDown('slow');

			}

			else{

				jQuery('.profileCont').slideUp('slow');	

			}

		});

		if(jQuery('#twitter_update_list').length > 0){	

		twitterLoad();

	}

	

});



function twitterLoad(){

	var e = document.createElement("script");

	e.src = 'http://twitter.com/javascripts/blogger.js';

	e.type="text/javascript";

	document.getElementsByTagName("head")[0].appendChild(e);



	intID=setInterval('twitterLoadCont()',1000);

}





function twitterLoadCont(){

	var e = document.createElement("script");

	e.src = 'http://twitter.com/statuses/user_timeline/Provfinewines.json?callback=twitterCallback2&count=3';

	e.type="text/javascript";

	document.getElementsByTagName("head")[0].appendChild(e);	

		

	clearInterval(intID);

	

	intID=setInterval('twitterAddClass()',1000);

	

}



function twitterAddClass(){

	//jQuery('.twitter_list li:first').css('display', 'none');

	jQuery('.twitter_list li:last').addClass('last');

	clearInterval(intID);

}



function validate_newsletter(){

	

		if(document.josForm.wpnewsletter_name.value==''){

			alert('Please complete Name.');

			return false;	

		} 

		else if(document.josForm.wpnewsletter_email.value==''){

			alert('Please complete Email.');

			return false;	

		}

		//return false;

}

function pauseBnr(i){clearInterval(intervalId[i])}

function playBnr(i){intervalId[i]=setInterval('startBnrPlay('+i+')', duration)}



function startBnrPlay(i){

	rotateObjP[i][curScrollDIV[i]].nextUL = (rotateObjP[i][curScrollDIV[i]].curUL == (rotateObjP[i][curScrollDIV[i]].totalUL-1))? 0 : rotateObjP[i][curScrollDIV[i]].curUL+1;

	moveBanner(elem, i, curScrollDIV[i], rotateObjP[i][curScrollDIV[i]].curUL, rotateObjP[i][curScrollDIV[i]].nextUL);

	rotateObjP[i][curScrollDIV[i]].curUL = rotateObjP[i][curScrollDIV[i]].nextUL;

}



function moveBanner(elem, pIndex, index, curBox, nextBox){

	jQuery('.scroll_cont:eq('+pIndex+') '+elem+':eq('+index+') > ul:eq('+curBox+')').stop(true,true).animate({top : (-1)*100+'px'},{

		queue:false,

		duration:'slow',

		step:function(n, fx){

			jQuery('.scroll_cont:eq('+pIndex+') '+elem+':eq('+index+') > ul:eq('+nextBox+')').css('top' , (n+100)+'px');

		}

	});

}



// Single Vertical Carousel 

$(function() {

$(".newsticker-jcarousellite").jCarouselLite({

        vertical: true,

        visible: 1,

        auto:6000,

        speed:1000

    });

});

// Vertical Carousel For Middle Content

$(function() {

$(".rotatingtext").jCarouselLite({

        /*vertical: true,*/

        visible: 1,

        auto:9000,

        speed:1000

    });

});



var Detector = function(){

	var h = document.getElementsByTagName("BODY")[0];

	var d = document.createElement("DIV");

	var s = document.createElement("SPAN");

	d.appendChild(s);

	d.style.fontFamily = "sans";			//font for the parent element DIV.

	s.style.fontFamily = "sans";			//serif font used as a comparator.

	s.style.fontSize   = "72px";			//we test using 72px font size, we may use any size. I guess larger the better.

	s.innerHTML        = "mmmmmmmmmmlil";		//we use m or w because these two characters take up the maximum width. And we use a L so that the same matching fonts can get separated

	h.appendChild(d);

	var defaultWidth   = s.offsetWidth;		//now we have the defaultWidth

	var defaultHeight  = s.offsetHeight;	//and the defaultHeight, we compare other fonts with these.

	h.removeChild(d);

	/* test

	 * params:

	 * font - name of the font you wish to detect

	 * return: 

	 * f[0] - Input font name.

	 * f[1] - Computed width.

	 * f[2] - Computed height.

	 * f[3] - Detected? (true/false).

	 */

	function debug(font) {

		h.appendChild(d);

		var f = [];

		f[0] = s.style.fontFamily = font;	// Name of the font

		f[1] = s.offsetWidth;				// Width

		f[2] = s.offsetHeight;				// Height

		h.removeChild(d);

		font = font.toLowerCase();

		if (font == "serif") {

			f[3] = true;	// to set arial and sans-serif true

		} else {

			f[3] = (f[1] != defaultWidth || f[2] != defaultHeight);	// Detected?

		}

		return f;

	}

	function test(font){

		f = debug(font);

		return f[3];

	}

	this.detailedTest = debug;

	this.test = test;	

}


