﻿///<reference path="jquery-1.3.2-vsdoc.js"/>

/* +++ GENERAL ALL-PAGE JS +++ */
$(document).ready(function() {

	// Replace links with buttons (do before Cufon and DD_belated)
	$('a[class^=BTNbtn]').each(function(i, e) {
		$(this).wrap('<span class="' + $(this).attr('class').substr(3) + '"></span>')
		.after('<span class="right"></span>')
		.attr('class', '');
		if ($.browser.msie && parseInt($.browser.version) <= 6) {
			$(this).hover(function() {
				$(this).add($(this).parent().add($(this).next())).css('background-position', 'left bottom');
			}, function() {
				$(this).add($(this).parent().add($(this).next())).css('background-position', 'left top');
			});
		}
	});

	if ($.browser.msie && parseInt($.browser.version) <= 6) {
		// Apply PNG-fix for IE6
		$("img[src$='png']").each(function() {
			if (!$(this).hasClass('noPngFix')) {
				DD_belatedPNG.fixPng(this);
			}
		});

		$('div, span, a, input, li, dt, ul').filter(function() {
			if ($(this).css('backgroundImage').match('.png') == '.png')
				return true;
			else
				return false;
		}).not('#topPlaceholder').each(function() {
			DD_belatedPNG.fixPng(this);
		});

		$('.navigationSearchSubmit, .footerSubmit input').hover(function() {
			$(this).css('background-position', 'left bottom !important');
		}, function() {
			$(this).css('background-position', 'left top !important');
		});

		// Fix init scrollable prevPage
		var prevPage = $('.prevPage');

		if (prevPage.length > 0) {
			prevPage.css('background-position', 'bottom');
			prevPage.attr('style', prevPage.attr('style').replace(/background-position.*m;/i, ''));
		}
	}

	$('.prevPage, .nextPage').click(function() {
		return false;
	});

	Cufon.replace('.btnGreyPlain a, .btnGrey a, .btnGreySmall a, .btnGreyMedium a, .btnGreyPlainTiny a', {
		fontFamily: 'boton',
		textShadow: '1px 1px #ffffff',
		hover: true
	});

	Cufon.replace('.btnBlackBig a, .btnBlack a, .btnBlackHalf a, .btnBlackOversized a', {
		fontFamily: 'boton',
		textShadow: '1px 1px #444444'
	});

	Cufon.replace('.btnGreen a, .btnGreenSmall a, .btnGreenMedium a, .btnGreenBig a', {
		fontFamily: 'boton',
		textShadow: '1px 1px #05540a'
	});

	Cufon.replace('.footer h4, .navigationLeftMenu span.top a, .t1000Carousel .menu a', { fontFamily: 'boton', hover: true });

	Cufon.replace('h1[class!=noCufon], h2[class!=noCufon], h3[class!=noCufon], h4[class!=noCufon], h5[class!=noCufon]', { fontFamily: 'boton' });
	Cufon.replace('#t4400 #login label, #t4400 .menu > a, .navigationDetails a, .navigationSubMenu a, .mainContentTopTabbs ul li h5', { fontFamily: 'botonRegular', hover: true });
	Cufon.replace('h3.nobold, h4.nobold,h5.nobold', { fontFamily: 'botonRegular' });
	Cufon.replace('.size1, .size2, .size3, .size4, .size5, .size6, .size7, ,.mainContentTopTabbs ul .selected h5', { fontFamily: 'boton', hover: true });
	Cufon.replace('.navigationPrePostPaid a', { fontFamily: 'boton', hover: true });

	String.prototype.trim = function() {
		return this.replace(/^\s+|\s+$/g, '');
	}

	// Text boxes and textfields
	$("input[type!='submit'], textarea").focus(function() {
		if (this.value == this.defaultValue)
			this.value = '';
	}).blur(function() {
		if (this.value.trim() == '')
			this.value = this.defaultValue;
	});

	// Select boxes
	$('select[class!=noSelect]').selectBox({
		'callOnLoad': function() { if ($.browser.msie && parseInt($.browser.version) <= 6) { DD_belatedPNG.fix('.sb-btn, .sb-top'); } },
		'callBack': function() { if ($.browser.msie && parseInt($.browser.version) <= 6) { DD_belatedPNG.fix('.sb-list , .sb-slideBottom'); } }
	});

	// Checkboxes and radio buttons
	if ($.fn.checkbox) {
		// disable for IE6 
		if (!$.browser.msie || ($.browser.msie && parseInt($.browser.version) > 6)) {
			$('input:checkbox').checkbox({
				empty: 'images/empty.png'
			});
			$('input:radio').checkbox({
				empty: 'images/empty.png',
				cls: 'jquery-radiobutton'
			});
		}
	}

	/* +++ DROP-DOWN-MENU +++ */

	var closeDropDownTimeOut;
	var closeDropDownWaitCount = 0;
	var closeDropDownWaitCountMax = 8;
	var delay = 100; // e.g. 200 ms * 10 = 2 sec

	var cS = { isHoveringSomething: 0, isHoveringDropDown: 1, isHoveringNothing: 2 };
	var cursorStatus = cS.isHoveringNothing;

	$('.navigationSubMenu a').hover(function() {
		cursorStatus = cS.isHoveringSomething;
		openDropDown(this);
	}, function() {
		cursorStatus = cS.isHoveringNothing;
		closeDropDown();
	});

	$('.navigationDropDown').hover(function() {
		cursorStatus = cS.isHoveringSomething;
	}, function() {
		cursorStatus = cS.isHoveringNothing;
		closeDropDown();
	});

	var openDropDown = function(obj) {
		var dropDown = $('.navigationDropDown');
		if ($('.navigation').offset().left > 0)
			var newLeft = $(obj).offset().left - $('.navigation').offset().left - 10 + 'px';
		else
			var newLeft = $(obj).offset().left - $('.navigationBusinessWrapper').offset().left - 10 + 'px';

		if (dropDown.css('top') != '117px' || dropDown.css('left') != newLeft) {
			var arr = $(obj).attr('class').split(' '), foundClass;

			for (var i = 0; i < arr.length; i++) {
				if (arr[i].match('navigationSubMenuItem') == 'navigationSubMenuItem') {
					foundClass = arr[i];
					break;
				}
			}

			$('.navigationDropDownContent:visible').hide();
			$('.' + foundClass + ':last').show();

			dropDown.queue([]).stop()
			.css({ 'left': newLeft, 'top': '-' + $('.navigationDropDown').height() + 'px' })
			.animate({
				top: '117px'
			}, 300, 'easeOutExpo');
		}


	};

	var closeDropDown = function() {
		if (cursorStatus != cS.isHoveringSomething) {
			clearTimeout(closeDropDownTimeOut);

			if (closeDropDownWaitCount >= closeDropDownWaitCountMax) {
				closeDropDownWaitCount = 0;
				closeDropDownDefinitely();
			}
			else if (closeDropDownWaitCount > 0) {
				closeDropDownWaitCount++;
				closeDropDownTimeOut = setTimeout(closeDropDown, delay);
			}
			else {
				closeDropDownWaitCount++;
				closeDropDownTimeOut = setTimeout(closeDropDown, delay);
			}
		}
	};

	var closeDropDownDefinitely = function() {
		$('.navigationDropDown').queue([]).stop().animate({
			top: '-' + $('.navigationDropDown').height() + 'px'
		}, 300, 'easeInExpo');
	};

	$('.navigationDropDownContent:visible').hide();

	/* --- DROP-DOWN-MENU --- */

	$(".lightBoxLayer .close").live("click", function() {
		hideLightBox();
		return false;
	});

	$('.shadowedTabs').tabs({
		collapsible: false,
		selected: 0,
		show: function() {
			Cufon.replace('.shadowedTabs .panelWrapper h5', { fontFamily: 'botonRegular' });
			Cufon.replace('.shadowedTabs .panelWrapper .ui-tabs-selected h5', { fontFamily: 'boton' });
			fixShowIE6();
			if($(".shadowedTabs a[href='#tab5']").parent().parent('li').hasClass('ui-tabs-selected')){
	            rnd = function(mi, ma) {
			        return Math.floor((ma-(mi-1))*Math.random()) + mi
		        };
		        $(".cordovan-bargraph .bars").cordovanBars([rnd(250, 500), rnd(250, 500), rnd(250, 500), rnd(250, 500), rnd(250, 500)], 10);
            }
		}
	});

	$(window).scroll(function() {
		positionLightBox();
	}).resize(function() {
		positionLightBox(true);
	});

	$(".lightBoxCurtainLayer").click(function() {
		hideLightBox();
	});

});



var T7100 = function() {
    $(".signInBox a").click(function(){
        $(".signInBox form").submit();
    });
};

t4050 = function(){

    $("#t4050 td").hover(function(){
        $(this).addClass("hoverBg");
    }, function(){
        $(this).removeClass("hoverBg");
    });

    $("#t4050 .big li:first").show();

    $("#t4050 td a").click(function(){
        a = $(this);
        $("#t4050 .big li").hide();
        href = a.attr("href");
        $("#t4050 .big #" + href.substr(1, href.length)).show();
        return false;
    });
    
};

t7000 = function(){
    
	$(".createWrapperHtml").cordovanTicker({
		wrapperClass: "cordovan-ticker"
	});

};


var positionLightBox = function(setPos) {
	if ($(".lightBoxLayer").is(":visible")) {
		win = jsTools.windowSize();
		div = jsTools.size($(".lightBoxLayer"));

		pos = {
			x: ((win.w / 2) - (div.w / 2)) + jsTools.scrollOffsetX(),
			y: ((win.h / 2) - (div.h / 2)) + jsTools.scrollOffsetY()
		};

		if (setPos) {
			$(".lightBoxLayer").css({
				"top": pos.y + "px",
				"left": pos.x + "px"
			});
		} else {
			$(".lightBoxLayer").stop().animate({
				"top": pos.y + "px",
				"left": pos.x + "px"
			});
		}
	}
};

var jsTools = {

	scrollOffsetY: function() {
		if (document.body.scrollTop == 0) {
			if (window.pageYOffset) {
				return window.pageYOffset;
			} else {
				return (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
			}
		}
		return document.body.scrollTop;
	},

	scrollOffsetX: function() {
		if (document.body.scrollLeft == 0) {
			if (window.pageXOffset) {
				return window.pageXOffset;
			} else {
				return (document.body.parentElement) ? document.body.parentElement.scrollLeft : 0;
			}
		}
		return document.body.scrollLeft;
	},

	scrollOffset: function() {
		return { x: jsTools.scrollOffsetX(), y: jsTools.scrollOffsetY() };
	},

	size: function(obj) {
		return { w: $(obj).width(), h: $(obj).height() };
	},

	windowSize: function() {
		return jsTools.size(window);
	}

};

var fixSeekIE6 = function() {
	if ($.browser.msie && parseInt($.browser.version) <= 6) {
		if (this.getRoot().parent().find('.prevPage').length > 0) {
			var prevPage = this.getRoot().parent().find('.prevPage');
			var nextPage = this.getRoot().parent().find('.nextPage');
		}
		else if (this.getRoot().parent().parent().find('.prevPage').length > 0) {
			var prevPage = this.getRoot().parent().parent().find('.prevPage');
			var nextPage = this.getRoot().parent().parent().find('.nextPage');
		}
		else if (this.getRoot().find('.prevPage').length > 0) {
			var prevPage = this.getRoot().find('.prevPage');
			var nextPage = this.getRoot().find('.nextPage');
		}
		else
			return true;

		// if active page is on the right - enable prevPage btn
		if (this.getPageIndex() > 0) {
			prevPage.css('background-position', 'top');
			prevPage.attr('style', prevPage.attr('style').replace(/background-position.*p;/i, ''));

		}
		else { // if active page is first page - disable prevPage btn
			prevPage.css('background-position', 'bottom');
			prevPage.attr('style', prevPage.attr('style').replace(/background-position.*m;/i, ''));

		}

		// if it's the last page - disable nextPage btn
		if (this.getPageIndex() == this.getPageAmount() - 1) {
			nextPage.css('background-position', 'bottom');
			nextPage.attr('style', nextPage.attr('style').replace(/background-position.*m;/i, ''));
		}
		else { // else, enable nextPage btn
			nextPage.css('background-position', 'top');
			nextPage.attr('style', nextPage.attr('style').replace(/background-position.*p;/i, ''));
		}
	}
};

var fixShowIE6 = function() {
	if ($.browser.msie && parseInt($.browser.version) <= 6) {
		$('.genericTabs > shape').hide();
		$('.genericTabs > shape:first').show().next().show();
		$('.genericTabs .content:visible, .genericTabs .contentNoPadding:visible').prev().show().prev().show();
	}
};

var showLightBox = function() {
	$(".lightBoxCurtainLayer").css("height", $(document).height() + "px").fadeIn("slow");
	$(".lightBoxLayer").fadeIn("slow");
	positionLightBox(true);
};

var hideLightBox = function() {
	$(".lightBoxLayer, .lightBoxCurtainLayer").fadeOut("slow");
};

/* --- GENERAL ALL-PAGE JS --- */

/* +++ TEMPLATE SPECIFIC +++ */

var T100 = function() {
	$('.smallGenericCarousel .nextPage, .smallGenericCarousel .prevPage').click(function() {
		return false;
	});

	$('.smallGenericCarousel .scrollPhones').scrollable({
		size: 5,
		prevPage: '.prevPage',
		nextPage: '.nextPage',
		easing: 'easeOutCirc',
		speed: 1000,
		keyboard: false,
		clickable: false,
		onSeek: fixSeekIE6
	});

	$('#accordion100 .header').click(function() {
		var that = $(this);
		var thatCH = that.children('.arrow');
		that.next().slideToggle('fast');
		if (thatCH.hasClass('openContainer')) {
			thatCH.removeClass('openContainer');
		} else {
			thatCH.addClass('openContainer');
		}
		return false;
	});

	/*   Carousel phone fix   */
	$('.expandBox').hide();
	var swi = false, memEle = false, leftOut = false, isCorner = false;
	var lastEle = $('#t100 .smallGenericCarousel .genericScrollable .items .products');
	if (lastEle.length <= 5) { $('.nextPage, .prevPage').hide() }
	var eleNr = (lastEle.length - 2);
	$('#t100 .smallGenericCarousel .genericScrollable .items div').click(function() {
		var that = $(this);
		$('.expandBox').hide();
		var thatExpobox = that.children('.expandBox');
		var hitNow = lastEle.index(this);
		//alert(hitNow);
		var theArr = [3, 4, 8, 9, 13, 14, 18, 19, 23, 24, 28, 29, 33, 34, 38, 39, 43, 44], theArrNr = $.inArray(hitNow, theArr);
		isCorner = (theArrNr == -1) ? false : true;
		if (that.width() < 180 && swi === false) {
			if (hitNow > eleNr || isCorner) {
				var item = $('.items');
				var itemOff = item.position().left;
				item.animate({ 'left': (itemOff - 135) + 'px' }, 300);
				leftOut = true;
			}
			that.animate({ 'width': '250px' }, 300);
			thatExpobox.show();
			swi = true;
			memEle = that;
		} else if (that.width() < 180 && swi === true) {
			if (leftOut) {
				var item = $('.items');
				var itemOff = item.position().left;
				item.animate({ 'left': (itemOff + 135) + 'px' }, 300);
				leftOut = false;
			}
			memEle.animate({ 'width': '116px' }, 300, function() {

				that.animate({ 'width': '250px' }, 300);
				if (hitNow > eleNr || isCorner) {
					var item = $('.items');
					var itemOff = item.position().left;
					item.animate({ 'left': (itemOff - 135) + 'px' }, 300);
					leftOut = true;
				}
				thatExpobox.show();
			});
			memEle = that;
			swi = true;
		} else if (that.width() > 180 && swi === true) {
			if (leftOut) {
				var item = $('.items');
				var itemOff = item.position().left;
				item.animate({ 'left': (itemOff + 135) + 'px' }, 300);
				leftOut = false;
			}
			that.animate({ 'width': '116px' }, 300, function() {
			});

			swi = false;
		}
	});

};



var T1000 = function() {
	swfobject.embedSWF("flash/carouselBgColorFade.swf", "topPlaceholder", "100%", "340", "8.0.0", false, { backgroundcolor: '0x00FF00' }, { wmode: 'opaque' });

	/* Scroll start */

	var scrolls = { Phones: 4, Subscriptions: 3, Bundles: 3, Accessories: 3 };
	var scrollNumber = 1;
	var timeout = 5000;
	var isClicked = false;
	$.each(scrolls, function(key, value) {
		$('.t1000Carousel .menu a[href=#' + key.toLowerCase() + ']').click(function() {
			showScroll(key);

			if (key == 'Phones') {
				scrollNumber = 1;
			}
			else if (key == 'Subscriptions') {
				scrollNumber = 2;
			}
			else if (key == 'Bundles') {
				scrollNumber = 3;
			}
			else if (key == 'Accessories') {
				scrollNumber = 0;
			}

			return false;
		});

		$('.t1000Carousel #scroll' + key).scrollable({
			size: value,
			prevPage: '#' + key.toLowerCase() + ' .prevPage',
			nextPage: '#' + key.toLowerCase() + ' .nextPage',
			easing: 'easeOutCirc',
			speed: 1000,
			keyboard: false,
			clickable: false,
			onSeek: fixSeekIE6
		});

		var itemsLength = $('.t1000Carousel #scroll' + key + ' .items > *').length;
		if (itemsLength <= value) {
			$('#' + key.toLowerCase() + ' .prevPage, #' + key.toLowerCase() + ' .nextPage').addClass('disabled');
		}
	});


	var showScroll = function(scroll) {
		$('.menu ul li').removeClass('selected');
		if ($.browser.msie && parseInt($.browser.version) <= 6) {
			$('.menu ul li[class!=selected] a').css('background-position', '-9999px');
		}

		$('.t1000Carousel .menu a[href=#' + scroll.toLowerCase() + ']').parent('h5').parent('li').addClass('selected');

		if ($.browser.msie && parseInt($.browser.version) <= 6) {
			$('.menu ul a[href=#' + scroll.toLowerCase() + ']').css('background-position', 'left');
		}

		$(".t1000Carousel .scroll").children().hide();
		$('#' + scroll.toLowerCase()).show();

		Cufon.replace('h5[class!=noCufon]', { fontFamily: 'boton' });
	}

	$('.t1000Carousel').hover(function() {
		clearTimeout(hoverCarousel);
	}, function() {
		if (isClicked != true) {
			clearTimeout(hoverCarousel);
			hoverCarousel = setTimeout(rollCarousel, timeout);
		}
	});

	$('.menu ul li a').click(function() {
		hoverCarousel = '';
		clearTimeout(hoverCarousel);
		isClicked = true;
	});

	var rollCarousel = function() {
		switch (scrollNumber) {
			case 0:
				showScroll('Phones');
				break;
			case 1:
				showScroll('Subscriptions');
				break;
			case 2:
				showScroll('Bundles');
				break;
			case 3:
				showScroll('Accessories');
				break;
			default:
				return false;
				break;
		}

		scrollNumber = scrollNumber + 1;

		if (scrollNumber == 4) {
			scrollNumber = 0;
		}

		clearTimeout(hoverCarousel);
		hoverCarousel = setTimeout(rollCarousel, timeout);
	};

	var hoverCarousel = setTimeout(rollCarousel, timeout);

	/* Scroll end */

	/* Plus Start */
	$('#plus .items div a ').tooltip({
		'calling': function() {
			Cufon.replace('.tooltipTitle', { fontFamily: 'boton' });
			if ($.browser.msie && parseInt($.browser.version) <= 6) { DD_belatedPNG.fix('.tooltipTop,.tooltipFoot'); }
		},
		'delayIn': 120,
		'title': true,
		'y': -36,
		'yPop': 10,
		'yOut': 60
	});

	$('#plus').scrollable({
		size: 7,
		prevPage: '.t1000CarouselPlus .prevPage',
		nextPage: '.t1000CarouselPlus .nextPage',
		easing: 'easeOutCirc',
		speed: 1000,
		keyboard: false,
		clickable: false,
		onSeek: fixSeekIE6
	});
	/* Plus End */
};

var T1100 = function() {

	$('.genericCarousel .nextPage, .genericCarousel .prevPage').click(function() {
		return false;
	});

	$('.genericCarousel .scrollSubscriptions, .genericCarousel .scrollPlusServices ').scrollable({
		size: 3,
		prevPage: '.prevPage',
		nextPage: '.nextPage',
		easing: 'easeOutCirc',
		speed: 1000,
		keyboard: false,
		clickable: false,
		onSeek: fixSeekIE6
	});

	$('.genericCarousel .scrollPhones').scrollable({
		size: 4,
		prevPage: '.prevPage',
		nextPage: '.nextPage',
		easing: 'easeOutCirc',
		speed: 1000,
		keyboard: false,
		clickable: false,
		onSeek: fixSeekIE6
	});
};

var T1110 = function() {

	$('.genericCarousel .nextPage, .genericCarousel .prevPage').click(function() {
		return false;
	});

	$('.genericCarousel .genericScrollable').scrollable({
		size: 3,
		prevPage: '.prevPage',
		nextPage: '.nextPage',
		easing: 'easeOutCirc',
		speed: 1000,
		keyboard: false,
		clickable: false,
		onSeek: fixSeekIE6
	});

};

var T1111 = function() {

	$('.genericCarousel .nextPage, .genericCarousel .prevPage').click(function() {
		return false;
	});

	$('.genericCarousel .genericScrollable').scrollable({
		size: 3,
		prevPage: '.prevPage',
		nextPage: '.nextPage',
		easing: 'easeOutCirc',
		speed: 1000,
		keyboard: false,
		clickable: false,
		onSeek: fixSeekIE6
	});

};

var T11111 = function() {

	$('.genericCarousel .nextPage, .genericCarousel .prevPage').click(function() {
		return false;
	});

	$('.genericCarousel .genericScrollable').scrollable({
		size: 3,
		prevPage: '.prevPage',
		nextPage: '.nextPage',
		easing: 'easeOutCirc',
		speed: 1000,
		keyboard: false,
		clickable: false,
		onSeek: fixSeekIE6
	});

	$('#tabBox').tabs({
		collapsible: false,
		selected: 0,
		show: function() {
			Cufon.replace('.genericTabs .top h5', { fontFamily: 'botonRegular' });
			Cufon.replace('.genericTabs .top .ui-tabs-selected h5', { fontFamily: 'boton' });
			fixShowIE6();
		}
	});

	$('#productScroll').scrollable({
		size: 1,
		easing: 'easeOutCirc',
		speed: 1000,
		keyboard: false,
		clickable: false,
		interval: 10000,
		loop: true
	});


	if ($('#productScroll .items div').size() <= 1) {
		$('.navi').hide();
	}

	$("#t11111 .compareToOther").click(function() {
		$(".lightBoxLayer").load("11111-HR-Mobile-Hero-Priceplan-Leve-AjaxPopup.htm", false, function() {
			showLightBox();
			Cufon.replace('h1[class!=noCufon], h2[class!=noCufon], h3[class!=noCufon], h4[class!=noCufon], h5[class!=noCufon]', { fontFamily: 'boton' });

			$(".lightBoxLayer .top, .lightBoxLayer .bottom, .lightBoxLayer .middle, .lightBoxLayer .close").each(function() {
				if (!$(this).hasClass('noPngFix')) {
					DD_belatedPNG.fixPng(this);
				}
			});

		});
		return false;
	});

};

var T1150 = function() {

	$('.genericCarousel .nextPage, .genericCarousel .prevPage').click(function() {
		return false;
	});

	$(' .genericCarousel .scrollPlusServices,.genericCarousel .scrollPlusServicesBig').scrollable({
		size: 3,
		prevPage: ' .prevPage',
		nextPage: ' .nextPage',
		easing: 'easeOutCirc',
		speed: 1000,
		keyboard: false,
		clickable: false,
		onSeek: fixSeekIE6
	});

	$('#tabBox').tabs({
		collapsible: false,
		selected: 0,
		show: function() {
			Cufon.replace('.genericTabs .top h5', { fontFamily: 'botonRegular' });
			Cufon.replace('.genericTabs .top .ui-tabs-selected h5', { fontFamily: 'boton' });
			fixShowIE6();
		}
	});

};



var T1200 = function() {

	$('.genericCarousel .nextPage, .genericCarousel .prevPage').click(function() {
		return false;
	});

	$('.genericCarousel .scrollSubscriptions, .genericCarousel .scrollPlusServices, .genericCarousel .scrollHardware').scrollable({
		size: 3,
		prevPage: ' .prevPage',
		nextPage: '.nextPage',
		easing: 'easeOutCirc',
		speed: 1000,
		keyboard: false,
		clickable: false,
		onSeek: fixSeekIE6
	});

};

var T1210 = function() {

	$('.genericCarousel .nextPage, .genericCarousel .prevPage').click(function() {
		return false;
	});

	$('.genericCarousel .genericScrollable').scrollable({
		size: 3,
		prevPage: '.prevPage',
		nextPage: '.nextPage',
		easing: 'easeOutCirc',
		speed: 1000,
		keyboard: false,
		clickable: false,
		onSeek: fixSeekIE6
	});
};

var T1120 = function() {
	$('.genericCarousel .nextPage, .genericCarousel .prevPage').click(function() {
		return false;
	});

	$('.genericCarousel .scrollPhones').scrollable({
		size: 3,
		prevPage: '.prevPage',
		nextPage: '.nextPage',
		easing: 'easeOutCirc',
		speed: 1000,
		keyboard: false,
		clickable: false,
		onSeek: fixSeekIE6
	});

	$('#showFilteredSelection').click(function() {
		/* NOT YET IMPLEMENTED (add slash at end of this line to enable) *
		$('#filteredResultContainer').load('http://url', function() {
		$(this).slideDown();
		});
		// */
		$('#filteredResultContainer').slideDown();
		return false;
	});
};

var T1130 = function() {
	T1120();
};

var T2000 = function() {
	T1000();
};

var T600 = function() {
	$("#t600 .article a").click(function() {
		$(".lightBoxLayer").load("600-News-Article.htm", false, function() {
			showLightBox();
		});

		return false;
	});
};

var T3000 = function() {
	$('.header').click(function() {
		var that = $(this);
		var thatCH = that.children('.arrow');
		that.next().slideToggle('fast');
		if (thatCH.hasClass('.openContainer')) {
			thatCH.removeClass('openContainer');
		} else {
			thatCH.addClass('openContainer');
		}
		return false;
	});
}

var T3100 = function() {
	$("#t3100 dl dt a").click(function() {
		$(this).closest("dl").children().removeClass("active");
		$(this).parent().next().andSelf().addClass("active");
		return false;
	});
};
var T21111 = function() {

	$('.genericCarousel .nextPage, .genericCarousel .prevPage').click(function() {
		return false;
	});

	$('.genericCarousel .genericScrollable').scrollable({
		size: 3,
		prevPage: '.prevPage',
		nextPage: '.nextPage',
		easing: 'easeOutCirc',
		speed: 1000,
		keyboard: false,
		clickable: false,
		onSeek: fixSeekIE6
	});

	$('#tabBox').tabs({
		collapsible: false,
		selected: 0,
		show: function() {
			Cufon.replace('.genericTabs .top h5', { fontFamily: 'botonRegular' });
			Cufon.replace('.genericTabs .top .ui-tabs-selected h5', { fontFamily: 'boton' });
			fixShowIE6();
		}
	});

	$('#productScroll').scrollable({
		size: 1,
		easing: 'easeOutCirc',
		speed: 1000,
		keyboard: false,
		clickable: false,
		interval: 10000,
		loop: true
	});


	if ($('#productScroll .items div').size() <= 1) {
		$('.navi').hide();
	}
};

var T1131 = function() {

	$('.thumbs li').click(function() {
		var obj = $(this);
		if (!obj.hasClass('selected')) {
			obj.parent().find('li').removeClass('selected');
			obj.parent().find('span').remove();

			if ($.browser.msie && parseInt($.browser.version) <= 8) {
				if ($.browser.msie && parseInt($.browser.version) <= 6) {
					obj.parent().find('shape').remove();
					var source = obj.find('img').attr('src');
					obj.parent().prev().find('shape').remove().find('img').remove();
					obj.parent().prev().append('<img class=\"preview\" src=\"' + source + '" alt=\"\" />');

					DD_belatedPNG.fix('.preview, .thumbs span');
				}
				else {
					obj.parent().prev('div').find('img').attr('src', obj.find('img').attr('src'));
				}
			}
			else {
				obj.parent().prev('div').find('img').fadeTo(400, 0.1, function() {
					obj.parent().prev('div').find('img').attr('src', obj.find('img').attr('src')).fadeTo(400, 1);
				});
			}
			obj.addClass('selected');
			obj.find('img').after('<span></span>');
		}
	});

	$('.genericCarousel .nextPage, .genericCarousel .prevPage').click(function() {
		return false;
	});

	$('.genericCarousel .genericScrollable').scrollable({
		size: 3,
		prevPage: '.prevPage',
		nextPage: '.nextPage',
		easing: 'easeOutCirc',
		speed: 1000,
		keyboard: false,
		clickable: false,
		onSeek: fixSeekIE6
	});

	$('#tabBox').tabs({
		collapsible: false,
		selected: 0,
		show: function() {
			Cufon.replace('.genericTabs .top h5', { fontFamily: 'botonRegular' });
			Cufon.replace('.genericTabs .top .ui-tabs-selected h5', { fontFamily: 'boton' });
			fixShowIE6();
		}
	});

	$('#productScroll').scrollable({
		size: 1,
		easing: 'easeOutCirc',
		speed: 1000,
		keyboard: false,
		clickable: false,
		interval: 10000,
		loop: true
	});

	if ($('#productScroll .items div').size() <= 1) {
		$('.navi').hide();
	}
};

var T3000cs = function() {
	$("#t3000cs dl dt a").click(function() {
		$(this).closest("dl").children().removeClass("active");
		$(this).parent().next().andSelf().addClass("active");
		return false;
	});

	$("#t3000cs .navigationSearchBox").bind("focus blur keyup", false, function() {
		var popupLayer = $("#t3000cs .popupLayer");
		if ($(this).val().length > 3) {
			popupLayer.show(500);
		} else {
			popupLayer.hide(500);
		}
	});
};
var T3160 = function() {
	$("#t3160 dl dt a").click(function() {
		$(this).closest("dl").children().removeClass("active");
		$(this).parent().next().andSelf().addClass("active");
		return false;
	});
};

var T9100 = function() {

        $("input").click(function(){
					        $(".cordovan-bargraph .bars").cordovanBars([rnd(250, 500), rnd(250, 500), rnd(250, 500), rnd(250, 500), rnd(250, 500)], 10);	
		})
		
        $(".cordovan-slider").cordovanSlider({
					"callback": function(slider, percent){
						
						percent *= 100;
						
						if(percent > 66.6) {
							realValue = (3 * 66.6) + (24 * (percent-66.6))
						} else {
							realValue = (3 * percent);
						}
						
						realValue = Math.round(realValue);
						
						if(realValue >= 1000)
							realValue = 1000;
						
						$(slider).parent().children("input").val(realValue + ' (' + Math.round(percent) + ' %)');
					}
		});

	};

var cufonDatePicker = function() {
	Cufon.replace('.ui-datepicker span, .ui-datepicker a', { fontFamily: 'boton' });
};

var T4020 = function() {
	$('#startTime, #endTime').datepicker({
		buttonText: 'Pick date',
		closeText: "<img src='images/0-calClose.png'>",
		prevText: "<script type='text/javascript'>cufonDatePicker();if(DD_belatedPNG) DD_belatedPNG.fix('.ui-datepicker, #arrowLeft, #arrowRight');<\/script><img src='images/0-calPrev.png' id='arrowLeft' />",
		nextText: "<img src='images/0-calNext.png' id='arrowRight' />",
		dateFormat: 'yyyy-mm-dd', // DO NOT CHANGE (OR ALSO CHANGE FORMAT IN onSelect)
		dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
		dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
		monthNames: ['January', 'February', 'Mars', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
		gotoCurrent: true,
		firstDay: 0,
		currentText: 'Today',
		showOn: 'both',
		showAnim: 'show',
		duration: '',
		buttonImage: 'images/0-dateTimeIcon.png',
		buttonImageOnly: true,
		showButtonPanel: true,
		onSelect: function(dateText, inst) {
			if (inst.currentDay.length > 2) {
				var correctDay = $(inst.currentDay).text();
				var correctMonth = inst.currentMonth + 1;

				if (correctDay < 10)
					correctDay = '0' + correctDay;
				if (correctMonth < 10)
					correctMonth = '0' + correctMonth;

				inst.input.val(inst.currentYear + '-' + correctMonth + '-' + correctDay);
			}
		}
	});
};

var T4400 = function() {
	$('.accordion4400 .header').click(function() {
		var that = $(this);
		var thatCH = that.children('.arrow');
		that.next().slideToggle('fast');
		if (thatCH.hasClass('openContainer')) {
			thatCH.removeClass('openContainer');
		} else {
			thatCH.addClass('openContainer');
		}
		return false;
	});
	$('#t4400 .menu .login').click(function() {
		$('#t4400 #login').toggle();
		return false;
	});
};

/* --- TEMPLATE SPECIFIC --- */

/*********** EXTRA ADDED BY TELE2 BIT TEAM *************/
$(document).ready(function() {
	$('.rightContent').find('div.H-devideLine:last').remove();
	$('select.dropnav').change(function() { window.location.href = $(this).val(); });
});
$(document).ready(function() {
	if ($('.timeTable').length === 0) { return; }
	if ($('.serviceSelect').length === 0) { return; }
	var dropHtml = '<select class="dropcontact">';
	var i = 0;
	$('.timeTable').each(function() {
		if (i !== 0) {
			$(this).hide();
		}
		dropHtml += '<option>' + $(this).attr('summary') + '</option>';
		i++;
	});
	dropHtml += '</select>';
	$('div.serviceCenterAddresses div.serviceSelect').html(dropHtml);
	$('select.dropcontact').change(function() {
		$('.timeTable:visible').hide();
		$("table[summary='" + $(this).val() + "']").show();
	});
	$('select[class!=noSelect]').selectBox({
		'callOnLoad': function() { if ($.browser.msie && parseInt($.browser.version) <= 6) { DD_belatedPNG.fix('.sb-btn, .sb-top'); } },
		'callBack': function() { if ($.browser.msie && parseInt($.browser.version) <= 6) { DD_belatedPNG.fix('.sb-list , .sb-slideBottom'); } }
	});

});

$(document).ready(function() {
	if ($('#t600').length === 0) { return; }
	var tempYear;
	var yearCounter = 0;
	var articleYears = new Array();
	var articles = $("#t600 .article").each(function() {
		var curYear = $(this).find('strong').text().substring(0, 4);
		if (tempYear !== curYear) {
			articleYears[yearCounter] = curYear;
			tempYear = curYear;
			yearCounter++;
		}
		$(this).next().remove();
		$(this).remove();
	});
	var tabsHTML = "";
	tabsHTML += '<div class="shadowedTabs">';
	tabsHTML += '<ul>';
	for (var i = 0; i < articleYears.length; i++) {
		tabsHTML += '<li><h5><a href="#year-' + articleYears[i] + '">' + articleYears[i] + '</a></h5></li>';
	}
	tabsHTML += '</ul>';
	for (var i = 0; i < articleYears.length; i++) {
		tabsHTML += '<div id="year-' + articleYears[i] + '"></div>';
	}
	$('#articles').html(tabsHTML);
	$(articles).each(function() {
		var curYear = $(this).find('strong').text().substring(0, 4);
		$('#articles').find('div[id=year-' + curYear + ']').append('<div class="article">' + $(this).html() + '</div><hr />');
	});
	$('.shadowedTabs').tabs({
		collapsible: false,
		selected: 0,
		show: function() {
			Cufon.replace('.shadowedTabs .panelWrapper h5', { fontFamily: 'botonRegular' });
			Cufon.replace('.shadowedTabs .panelWrapper .ui-tabs-selected h5', { fontFamily: 'boton' });
			fixShowIE6();
		}
	});
	$("#t600 .article a").click(function() {
		$(".lightBoxLayer").load($(this).attr('href') + '#newsView #t600lightbox', false, function() {
			showLightBox();
		});
		return false;
	});
});
