displayNoneHTML();

$(document).ready(function() {

	// logo Click
	$("#header h1 a").click(function() {
		setInstantCookie("jumboWall_PL", 0);
	});

	// cookie logIn or logOut Check
	$.fe_logInOut();

	if ( $("#gnbp3").length ) $("#gnbp3").fe_gnb();

	// layerPopup
	if ( $(".layPopOpener").length ) {
		$.fe_lay({
			triggerClass : ".layPopOpener",
			targetClass : ".layPop",
			type : "overlay",
			overLay_Center : false,
			overLay_animationSpeed : 100
		});
	}

	// bandWidth
	checkBandWidth();

	// feedBack
	$.fe_feedBack();


	/********************************/

	navigation();

	if ( !isMobile && checkBandWidthVar != "Low" ) {

		expandTooltip();

		sectionInit();

		theLatest();
		mobileDevices();
		tvAudioVideo();
		cameraCamcorder();
		notebooksDisplay();
		homeAppliances();

		smallWall();
	} else {
		lowBandWidth();
	}

	if ( isMobile ) {
		$("#jumboWall").addClass("mobileFix");
	}

	learnMore();

	indexTab();

	section0();

	twitterInit();

	// reviewAPI
	reviewAPI();

	// IE6 NOT SUPPORT
	$.fe_ie6NotSupport();

});

recentlyViewedText = "Ostatnio oglądane";

var flashKV = new Object();
var flashReady = "collapse";

function flContentOnReady( id, success ) {
	flashKV[id] = document.getElementById(success);
	flashKV[id].setCondition( flashReady, 0);
}

function displayNoneHTML() {
	var displayNoneHTML = '<style type="text/css">'
								+ '#gnbp3 .menu { display:none;}'
								+ '.con #gnbp3 ul { margin:0; padding:0;}'
								+ '.con #gnbp3 ul li a {height:41px; padding:37px 22px 2px 22px;}'
								+ '.con #gnbp3 ul li.gnb1,'
								+ '.con #gnbp3 ul li.gnb2,'
								+ '.con #gnbp3 ul li.gnb3,'
								+ '.con #gnbp3 ul li.gnb4 {float:left;}'
								+ '.con #gnbp3 ul li.gnb1 {margin:0 0 0 38px;}'
								+ '#jumboWall { position:relative; width:960px; height:488px; margin-top:-12px; margin-bottom:100px; margin-left:auto; margin-right:auto; background:url(/pl/common/img/index/bg_blue.jpg) no-repeat center top; }'
								+ '#jumboWall .visualArea { display:none}';

	if ( $.browser.msie ) {
		if ( $.browser.version < 8 ) {
			displayNoneHTML += '.con .gnbp#gnbp3 { left:0px;}';
		}
	}
	displayNoneHTML += '</style>';
	document.write(displayNoneHTML);
}

function lowBandWidth() {
	var $section = $(".visualArea").find(".section0");

	$section.each(function() {

		$(this).find(".textLayer").hide();

		var desc1_Text = $(this).find(".description01").html();
		var Alink = $(this).find(".link").find("a").attr("href");
		var Atarget = $(this).find(".link").find("a").attr("target");
		var descHTML = '<a href="' + Alink + '">' + desc1_Text + '</a>';

		$(this).find(".description01").html(descHTML);
		if ( Atarget ) $(this).find(".description01").find("a").attr("target", Atarget);

		$(this).find(".title02").remove();
		$(this).find(".description02").remove();
		$(this).find(".link").remove();

	});

	// smallWall
	var $wall = $("#jumboWall").find(".section");

	$wall.each(function() {

		var checkMobileSection = $(this).parent().attr("id") == "mobileDevices" ? true : false;

		var $link = $(this).find("a").filter(function() {
			if ( !$(this).parent().hasClass("btnClose") ) {
				return $(this);
			}
		});

		$link.each(function() {
			if ( $(this).parent().hasClass("btnLearnMore") ) {
				$("<img />", {
					"class" : "endArrow",
					"src" : "/pl/common/img/index/ico_endarrow2.png"
				}).appendTo($(this));
			} else {
				if ( checkMobileSection ) {
					$("<img />", {
						"class" : "endArrow",
						"src" : "/pl/common/img/index/ico_endarrow.png"
					}).appendTo($(this));
				} else {
					$("<img />", {
						"class" : "endArrow",
						"src" : "/pl/common/img/index/ico_endarrow.png"
					}).appendTo($(this));
				}
			}
		});

		if ( !isMobile ) {

			$(this).bind({
				click : function() {
					if ( !$(this).find("a").length ) return false;
					if ( $(this).find("a").attr("target") == "_blank" ) {
						window.open($(this).find("a").attr("href"));
					} else {
						location.href = $(this).find("a").attr("href");
					}
					return false;
				},
				mouseenter : function() {
					if ( !$(this).find("a").length ) return false;
					$(this).css({
						"cursor" : "pointer"
					});
					if ( $(this).find("a").hasClass("noColor") ) return false;
					$(this).find(".textStyle03").find("a").css({
						"color" : "#0c4da2"
					});
					if ( checkMobileSection ) {
						$(this).find(".description").find("a").css({
							"color" : "#0c4da2"
						});
					} else {
						$(this).find(".description").find("a").css({
							"color" : "#0c4da2"
						});
					}
					$link.find(".endArrow").show();
				},
				mouseleave : function() {
					if ( !$(this).find("a").length ) return false;
					if ( $(this).find("a").hasClass("noColor") ) return false;
					$(this).find(".textStyle03").find("a").css({
						"color" : "#000"
					});
					if ( checkMobileSection ) {
						$(this).find(".description").find("a").css({
							"color" : "#000"
						});
					} else {
						$(this).find(".description").find("a").css({
							"color" : "#000"
						});
					}
					$link.find(".endArrow").hide();
				}
			});

		} else {
			$(this).bind({
				click : function() {
					if ( !$(this).find("a").length ) return false;
					if ( $(this).find("a").attr("target") == "_blank" ) {
						window.open($(this).find("a").attr("href"));
						return false;
					} else {
						location.href = $(this).find("a").attr("href");
					}
				}
			});

		}


	});

}

function smallWall() {

	var $wall = $("#jumboWall").find(".section");

	$wall.each(function() {

		var checkMobileSection = $(this).parent().attr("id") == "mobileDevices" ? true : false;

		var $link = $(this).find("a").filter(function() {
			if ( !$(this).parent().hasClass("btnClose") && !$(this).parent().hasClass("link") ) {
				return $(this);
			}
		});
		var $desc = $(this).find(".description01");

		$(this).find(".link").each(function() {
			$("<img />", {
				"class" : "endArrow",
				"src" : "/pl/common/img/index/ico_endarrow3.png"
			}).appendTo($(this).find("a")).show();
		});

		$link.each(function() {
			if ( $(this).parent().hasClass("btnLearnMore") ) {
				$("<img />", {
					"class" : "endArrow",
					"src" : "/pl/common/img/index/ico_endarrow2.png"
				}).appendTo($(this));
			} else {
				$("<img />", {
					"class" : "endArrow",
					"src" : "/pl/common/img/index/ico_endarrow.png"
				}).appendTo($(this));
			}
		});
		$desc.each(function() {
			if ( checkMobileSection ) {
				$("<img />", {
					"class" : "endArrow",
					"src" : "/pl/common/img/index/ico_endarrow.png"
				}).appendTo($(this));
			} else {
				$("<img />", {
					"class" : "endArrow",
					"src" : "/pl/common/img/index/ico_endarrow.png"
				}).appendTo($(this));
			}
		});


		$(this).bind({
			click : function() {
				if ( !$(this).find("a").length ) return false;
				if ( !$(this).hasClass("section0") ) {
					if ( $(this).find("a").attr("target") == "_blank" ) {
						window.open($(this).find("a").attr("href"));
					} else {
						location.href = $(this).find("a").attr("href");
					}
					return false;
				}
			},
			mouseover : function() {
				if ( !$(this).find("a").length ) return false;
				$(this).css({
					"cursor" : "pointer"
				});
				if ( $(this).find("a").hasClass("noColor") ) return false;
				$(this).find(".textStyle03").find("a").css({
					"color" : "#0c4da2"
				});
				$link.find(".endArrow").show();
				$desc.find(".endArrow").show();

			},
			mouseout : function() {
				if ( !$(this).find("a").length ) return false;
				if ( $(this).find("a").hasClass("noColor") ) return false;
				$(this).find(".textStyle03").find("a").css({
					"color" : "#000"
				});
				$link.find(".endArrow").hide();
				$desc.find(".endArrow").hide();
			}
		});


	});
}

function section0() {

	var $section = $("#jumboWall").find(".section0");

	$section.each(function(i) {
		$(this).bind({
			mouseover : function() {
				if ( i != 1 ) {
					$(this).find(".description01").css({
						"color" : "#0c4da2"
					});
				} else {
					$(this).find(".description01").css({
						"color" : "#0c4da2"
					});
				}
			},
			mouseout : function() {
				if ( i != 1 ) {
					$(this).find(".description01").css({
						"color" : "#000"
					});
				} else {
					$(this).find(".description01").css({
						"color" : "#000"
					});
				}
			}
		});
	});

}

function reviewAPI() {
	var xmlUrl = "/pl/api/type/top-rated/00000000?mType=xml&count=4";
	var $review = $("#reviews");
	var reviewHTML = "";
	var summHTML = '<div class="summ">'
				+ '<p class="figure">'
				+ '<a href="#none"><img src="" alt="" /></a>'
				+ '</p>'
				+ '<div class="infoArea">'
				+ '<div class="basicInfo">'
				+ '<h3><a href="#none"></a></h3>'
				+ '</div>'
				+ '<p class="rating">'
				+ '<span class="small point"><strong style="width:0px"></strong></span>'
				+ '<span class="review">(<a href="#none"></a>)</span>'
				+ '</p>'
				+ '<p class="ratingText"></p>'
				+ '</div>'
				+ '</div>';
	$review.html(
		'<h2>Top Rated</h2>'
		+ '<div class="summList">'
		+ '</div>'
	);
	for ( i=0; i < 4; i++) {
		reviewHTML += summHTML;
	}
	$review.find(".summList").html(reviewHTML);
	$.ajax({
		type: "GET",
		url: xmlUrl,
		dataType: "xml",
		error: function(){
			//alert("Error Loading XML Document");
		},
		success: function(xml) {
			var $summ = $("#reviews").find(".summ");
			$(xml).find("product").each(function(i){
				var title = $(this).attr("displayName");
				var url = $(this).find("url").text();
				var imageSrc = $(this).find("image").attr("src");
				var imageAlt = $(this).find("image").attr("alt");
				var starGrade = Math.round($(this).find("review").attr("rating") * 10) / 10;
				var rating = (starGrade > 0) ? (starGrade * 13) + Math.ceil(starGrade - 1) : 0;
				var reviewCount = $(this).find("review").attr("review-count");
				var reviewLink = $(this).find("review").attr("link");
				var $title = $summ.eq(i).find("h3").find("a");
				var $image = $summ.eq(i).find(".figure");
				var $rating = $summ.eq(i).find(".rating");
				$title.html(title);
				$title.attr("href", url);
				$image.find("a").attr("href", url);
				$image.find("img").attr("src", imageSrc);
				$image.find("img").attr("alt", imageAlt);
				$rating.find(".point").find("strong").css("width", rating + "px").text(starGrade);
				$rating.find(".review").find("a").text(reviewCount).attr("href", reviewLink);
				$rating.next().text(starGrade + " of 5");
			});
			$("#reviews").find("a").click(function() {
				s_control_click('events,eVar44', 'event46', 'event46,home:reviews', 'o', 'additional user interaction');
			});
		}
	});
}



function sectionInit() {

	var $section = $("#jumboWall").find(".section0");
	var $close = $("#jumboWall").find(".btnClose");
	var $animating = $("#jumboWall").find("*:animated");

	$section.removeClass("open").removeClass("expanded");
	$close.hide();
	$animating.stop(true, true);

	flashReady = "collapse";

	// theLatest
	$section.eq(0).css({
		"width" : "575px"
	});

	$section.eq(0).find(".title").eq(1).css({
		"bottom" : "-800px"
	});
	$section.eq(0).find(".description").eq(1).css({
		"bottom" : "-800px"
	});
	$section.eq(0).find(".link").css({
		"bottom" : "-800px"
	});

	$section.eq(0).find(".title").eq(0).css({
		"display" : "block",
		"left" : "30px"
	});
	$section.eq(0).find(".description").eq(0).css({
		"display" : "block",
		"left" : "30px"
	});

	// mobileDevices
	$section.eq(1).css({
		"width" : "575px",
		"left" : "193px"
	});
	$section.eq(1).find(".image").css({
		"left" : "-192px"
	});

	$section.eq(1).find(".title").eq(1).css({
		"left" : "-800px"
	});
	$section.eq(1).find(".description").eq(1).css({
		"left" : "-800px"
	});
	$section.eq(1).find(".link").css({
		"left" : "-800px"
	});

	$section.eq(1).find(".title").eq(0).css({
		"display" : "block",
		"left" : "30px"
	});
	$section.eq(1).find(".description").eq(0).css({
		"display" : "block",
		"left" : "30px"
	});



	// tvAudioVideo
	$section.eq(2).css({
		"width" : "575px"
	});
	$section.eq(2).find(".title").eq(1).css({
		"left" : "-800px"
	});
	$section.eq(2).find(".description").eq(1).css({
		"left" : "-800px"
	});
	$section.eq(2).find(".link").css({
		"left" : "-800px"
	});

	$section.eq(2).find(".title").eq(0).css({
		"display" : "block",
		"left" : "30px"
	});
	$section.eq(2).find(".description").eq(0).css({
		"display" : "block",
		"left" : "30px"
	});

	// cameraCamcorder
	$section.eq(3).css({
		"width" : "383px"
	});
	$section.eq(3).find(".title").eq(1).css({
		"left" : "-800px"
	});
	$section.eq(3).find(".description").eq(1).css({
		"left" : "-800px"
	});
	$section.eq(3).find(".link").css({
		"left" : "-800px"
	});

	$section.eq(3).find(".title").eq(0).css({
		"display" : "block",
		"left" : "30px"
	});
	$section.eq(3).find(".description").eq(0).css({
		"display" : "block",
		"left" : "30px"
	});

	// notebooksDisplay
	$section.eq(4).css({
		"width" : "575px",
		"left" : "193px"
	});
	$section.eq(4).find(".image").css({
		"left" : "-192px"
	});

	$section.eq(4).find(".title").eq(1).css({
		"left" : "-800px"
	});
	$section.eq(4).find(".description").eq(1).css({
		"left" : "-800px"
	});
	$section.eq(4).find(".link").css({
		"left" : "-800px"
	});

	$section.eq(4).find(".title").eq(0).css({
		"display" : "block",
		"left" : "30px"
	});
	$section.eq(4).find(".description").eq(0).css({
		"display" : "block",
		"left" : "30px"
	});


	// homeAppliances
	$section.eq(5).css({
		"width" : "575px"
	});

	$section.eq(5).find(".title").eq(1).css({
		"left" : "-800px"
	});
	$section.eq(5).find(".description").eq(1).css({
		"left" : "-800px"
	});
	$section.eq(5).find(".link").css({
		"left" : "-800px"
	});

	$section.eq(5).find(".title").eq(0).css({
		"display" : "block",
		"left" : "30px"
	});
	$section.eq(5).find(".description").eq(0).css({
		"display" : "block",
		"left" : "30px"
	});


}

function navigation() {

	var $jumboWall = $("#jumboWall, #header");
	var $navi = $("#jumboWall .navigation");
	var $depth1 = $navi.find("ul.depth1");
	var $trigger = $navi.find("li.depth1");
	var $depth2 = $trigger.find("ul.depth2");
	var $arrow = $navi.find(".hoverArrow");
	var $visualArea = $("#jumboWall .visualArea");
	var thisIdx = getCookie("jumboWall_PL");
	var rollTimer;
	var autoRollDelay = 8000;
	var nowIdx = 0;
	var hashWord = [
			"latest-home",
			"mobile-phone-home",
			"tv-audio-video-home",
			"camera-camcoder-home",
			"pc-peripherals-prtinters-home",
			"home-appliances-home"
	];

	if ( thisIdx == ""   ) {
		thisIdx = 0;
	} else {
		parseInt(thisIdx, 10);
	}

	nowIdx = parseInt(thisIdx, 10);

	window.location.hash = hashWord[thisIdx];

	$visualArea.eq(thisIdx).addClass("nowPlaying").show();

	wallBGInit(thisIdx);

	$depth1.removeClass().addClass("depth1 hoverMenu" + thisIdx);
	$depth2.hide();
	$trigger.eq(thisIdx).next().show();
	$arrow.removeClass().addClass("hoverArrow hoverMenu"+thisIdx);
	$trigger.eq(thisIdx).find("ul.depth2").show();

	if ( rollTimer ) clearInterval(rollTimer);
	rollTimer = setInterval(rolling, autoRollDelay);

	$jumboWall.bind({
		mouseover : function() {
			clearInterval(rollTimer);
		},
		mouseout : function() {
			if ( rollTimer ) clearInterval(rollTimer);
			rollTimer = setInterval(rolling, autoRollDelay);
		}
	});

	$trigger.each(function(i) {
		$(this).children("a").bind({
			mouseenter : function() {
				$navi.removeClass().addClass("navigation hoverMenu"+i);
			},
			mouseleave : function() {
				$navi.removeClass().addClass("navigation");
			},
			click : function() {

				nowIdx = i;

				setInstantCookie("jumboWall_PL", i);

				wallBGInit(i);

				var $content = $($(this).attr("href"));

				if ( $content.hasClass("nowPlaying") ) {
					return false;
				} else {
					$visualArea.removeClass("nowPlaying");
					$content.addClass("nowPlaying");
				}

				if ( !isMobile && checkBandWidthVar != "Low" ) sectionInit();

				$depth1.removeClass().addClass("depth1");
				$(this).parent().parent().addClass("hoverMenu"+i);
				$depth2.hide();
				$(this).next().show();
				$arrow.removeClass().addClass("hoverArrow hoverMenu"+i);

				$visualArea.hide();
				$content.show();

				window.location.hash =  hashWord[i];

				return false;
			}
		});
	});

	function rolling () {

		nowIdx += 1;

		if ( nowIdx == 6 ) nowIdx = 0;

		setInstantCookie("jumboWall_PL", nowIdx);

		wallBGInit(nowIdx);

		var $content = $($trigger.eq(nowIdx).children("a").attr("href"));

		if ( $content.hasClass("nowPlaying") ) {
			return false;
		} else {
			$visualArea.removeClass("nowPlaying");
			$content.addClass("nowPlaying");
		}

		if ( !isMobile && checkBandWidthVar != "Low" ) sectionInit();

		$depth1.removeClass().addClass("depth1");
		$trigger.eq(nowIdx).children("a").parent().parent().addClass("hoverMenu"+nowIdx);
		$depth2.hide();
		$trigger.eq(nowIdx).children("a").next().show();
		$arrow.removeClass().addClass("hoverArrow hoverMenu"+nowIdx);

		/*
		$content.show().css({
			"opacity" : 1,
			"z-index" : 100
		});

		$visualArea.eq(nowIdx-1).animate({
			"opacity" : 0
		}, 1000, function() {
			$(this).hide().css({
				"z-index" : 100
			});
			$content.css("z-index",150);
		});
		*/
		sectionInit();

		$visualArea.hide();
		$content.show();

		window.location.hash = hashWord[nowIdx];

	}

}

function wallBGInit(idx) {

	var flashIdx = parseInt(idx, 10) + 1;
	var flashFileName = "";
	var $visualArea = $("#jumboWall .visualArea");

	$visualArea.eq(idx).find(".section").each(function(i) {
		if ( i != 0 ) {
			if ( !$(this).hasClass("bg_Section" + i) ) {
				$(this).addClass("bg_Section"+i);
			}
		}
	});

	switch ( flashIdx ) {
		case 1 :
			flashFileName = "the_latest";
			break;
		case 2 :
			flashFileName = "mobile_devices";
			break;
		case 3 :
			flashFileName = "tv_av";
			break;
		case 4 :
			flashFileName = "camera_camcoder";
			break;
		case 5 :
			flashFileName = "notebooks_display";
			break;
		case 6 :
			flashFileName = "home_appliances";
			break;

	}

	var flashHTML = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="960" height="489" name="kv_loader_ie' + flashIdx +'" id="kv_loader_ie' + flashIdx + '" align="middle">'
						+	'<param name="movie" value="/pl/common/img/index/contents/kv_loader.swf" />'
						+	'<param name="quality" value="high" />'
						+	'<param name="bgcolor" value="#ffffff" />'
						+	'<param name="play" value="true" />'
						+	'<param name="loop" value="true" />'
						+	'<param name="wmode" value="opaque" />'
						+	'<param name="scale" value="showall" />'
						+	'<param name="menu" value="true" />'
						+	'<param name="devicefont" value="false" />'
						+	'<param name="salign" value="" />'
						+	'<param name="flashvars" value="id=kv' + flashIdx + '&amp;swf=/pl/common/img/index/contents/kv_' + flashFileName + '.swf" />'
						+	'<param name="allowScriptAccess" value="always" />'
						+	'<!--[if !IE]>-->'
						+	'<object type="application/x-shockwave-flash" data="/pl/common/img/index/contents/kv_loader.swf" width="960" height="489" name="kv_loader' + flashIdx + '" id="kv_loader' + flashIdx + '">'
						+		'<param name="movie" value="/pl/common/img/index/contents/kv_loader.swf" />'
						+		'<param name="quality" value="high" />'
						+		'<param name="bgcolor" value="#ffffff" />'
						+		'<param name="play" value="true" />'
						+		'<param name="loop" value="true" />'
						+		'<param name="wmode" value="opaque" />'
						+		'<param name="scale" value="showall" />'
						+		'<param name="menu" value="true" />'
						+		'<param name="devicefont" value="false" />'
						+		'<param name="salign" value="" />'
						+		'<param name="flashvars" value="id=kv' + flashIdx +'&amp;swf=/pl/common/img/index/contents/kv_' + flashFileName + '.swf" />'
						+		'<param name="allowScriptAccess" value="always" />'
						+	'<!--<![endif]-->'
						+		'<a href="http://www.adobe.com/go/getflash" class="adobeIcon">'
						+			'<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />'
						+		'</a>'
						+	'<!--[if !IE]>-->'
						+	'</object>'
						+	'<!--<![endif]-->'
						+'</object>';


		if ( isMobile || checkBandWidthVar == "Low" ) {
			if ( !$visualArea.eq(idx).find(".image").hasClass("bg_lowband") ) {
				$visualArea.eq(idx).find(".image").html("");
				$visualArea.eq(idx).find(".image").addClass("bg_lowband");
			}
		} else {
			$visualArea.eq(idx).find(".image").html(flashHTML);
		}
}

function expandTooltip() {

	var $expand = $("<div />", { "id" : "expandTooltip"});
	$expand.prependTo($("body"));
	$expand.html('<p>KLIKNIJ I POWIĘKSZ</p>').hide();

	$("#jumboWall .section0").each(function() {
		$(this).bind({
			mousemove : function(e) {
				var xPos = e.pageX + 10;
				var yPos = e.pageY + 20;
				$expand.animate({
					"left" : xPos + "px",
					"top" : yPos + "px"
				}, 0);
			}
		});
	});

	$("#jumboWall .section").not(".section0").each(function() {
		$(this).bind({
			mouseover : function() {
				$expand.hide();
			}
		});
	});

	$("#jumboWall .navigation").bind({
		mouseover : function() {
			$expand.hide();
		}
	});

}


function learnMore() {
	var $section = $(".visualArea").find(".section").filter(function() {
		if ( !$(this).hasClass(".section0") ) {
			return $(this);
		}
	});

	$section.each(function() {
		$(this).bind({
			mouseenter : function() {
				$(this).find(".btnLearnMore").stop(true, true).delay(150).animate({
					"left" : 0
				}, 300);
			}
		});
	});

	$section.each(function() {
		$(this).bind({
			mouseleave : function() {
				$(this).find(".btnLearnMore").stop(true, true).animate({
					"left" : "-125px"
				}, 300);
			}
		});
	});
}


function theLatest() {

	var $section = $("#theLatest").find(".section");
	var $btnClose = $section.eq(0).find(".btnClose");
	var $h4 = $section.eq(0).find("h4");
	var $desc = $section.eq(0).find(".description");
	var $link = $section.eq(0).find(".link");
	var $learnMore = $("#theLatest").find("p.btnLearnMore");
	var expandable = true;
	var clickable = true;
	var $expand = $("#expandTooltip");

	$btnClose.find("a").click(function(e) {
		e.stopPropagation();
		$btnClose.fadeOut(50);
		textHide();
		$expand.show();
		$section.eq(0)
			.animate({
				"width" : "575px"
			}, {
				duration: 1100,
				easing: "easeOutExpo"
			})
			.removeClass("open");
		flashReady = "collapse";
		flashKV.kv1.setCondition("collapse");
		return false;
	});

	$section.eq(0).bind({
		mouseenter : function() {
			if ( !$(this).hasClass("open") ) {
				$expand.show();
			}
			if ( !$(this).hasClass("expanded") ) {
				if ( !$(this).hasClass("open") ) {
					$(this).stop(true, true).animate({
						"width" : "600px"
					}, 200, function() {
					});
					$(this).addClass("expanded");
					flashReady = "over";
					flashKV.kv1.setCondition("over");
				}
			}
		},
		mouseleave : function() {
			if ( $(this).hasClass("expanded") ) {
				if ( !$(this).hasClass("open") ) {
					$(this).animate({
						"width" : "575px"
					}, 200, function() {

					});
					$(this).removeClass("expanded");
					flashReady = "collapse";
					flashKV.kv1.setCondition("collapse");
				}
			}
			$expand.hide();
		},
		click : function(e) {
			if ( clickable ) {
				clickable = false;
				if ( !$(this).hasClass("open") ) {
					textShow();
					$expand.hide();
					$section.eq(0).animate({
						"width" : "960px"
					}, {
						duration: 1100,
						easing: "easeOutExpo",
						complete : function() {
							$btnClose.fadeIn(50);
							expandable = false;
						}
					})
					.addClass("open");
					flashReady = "expand";
					flashKV.kv1.setCondition("expand");
				} else {
					$btnClose.fadeOut(50);
					textHide();
					$expand.show();
					$section.eq(0)
						.animate({
							"width" : "575px"
						}, {
							duration: 1100,
							easing: "easeOutExpo"
						})
						.removeClass("open");
					flashReady = "collapse";
					flashKV.kv1.setCondition("collapse");
				}
			}
		}
	});


	function textShow() {

		$desc.eq(0).stop(true, true).fadeOut(150);

		$h4.eq(0).stop(true, true).fadeOut(150, function() {
			$h4.eq(1).stop(true, true).delay(150).animate({
				"bottom" : "341px"
			}, {
				duration: 800,
				easing: "easeOutExpo"
			});

			$desc.eq(1).stop(true, true).animate({
				"bottom" : "200px"
			}, {
				duration: 1200,
				easing: "easeOutExpo",
				complete : function() {

				}
			});

			$link.stop(true, true).animate({
				"bottom" : "167px"
			}, {
				duration: 1500,
				easing: "easeOutExpo",
				complete : function() {
					clickable = true;
				}
			});

		});

	}

	function textHide() {

		$desc.eq(1).stop(true, true).animate({
			"bottom" : "-800px"
		},{
			duration: 700,
			easing: "easeOutExpo"
		});

		$link.stop(true, true).animate({
			"bottom" : "-800px"
		},{
			duration: 700,
			easing: "easeOutExpo"
		});

		$h4.eq(1).stop(true, true).animate({
			"bottom" : "-800px"
		}, {
			duration: 700,
			easing: "easeOutExpo",
			complete : function() {
				$desc.eq(0).fadeIn(350);
				$h4.eq(0).fadeIn(350, function() {
					clickable = true;
					expandable = true;
				});
			}
		});

	}

}

function mobileDevices() {

	var $section = $("#mobileDevices").find(".section");
	var $btnClose = $section.eq(0).find(".btnClose");
	var $h4 = $section.eq(0).find("h4");
	var $desc = $section.eq(0).find(".description");
	var $link = $section.eq(0).find(".link");
	var $learnMore = $("#mobileDevices").find("p.btnLearnMore");
	var expandable = true;
	var clickable = true;
	var $expand = $("#expandTooltip");

	$btnClose.find("a").click(function(e) {
		e.stopPropagation();
		$btnClose.fadeOut(50);
		textHide();
		$expand.show();
		$section.eq(0)
			.animate({
				"width" : "575px",
				"left" : "193px"
			}, {
				duration: 1100,
				easing: "easeOutExpo"
			})
			.removeClass("open");
		$section.eq(0).find(".image").animate({
			"left" : "-192px"
		}, {
			duration: 1100,
			easing: "easeOutExpo"
		});
		flashReady = "collapse";
		flashKV.kv2.setCondition("collapse");
		return false;
	});

	$section.eq(0).bind({
		mouseenter : function() {
			if ( !$(this).hasClass("open") ) {
				$expand.show();
			}
			if ( !$(this).hasClass("expanded") ) {
				if ( !$(this).hasClass("open") ) {
					$(this).stop(true, true).animate({
						"width" : "600px",
						"left" : "193px"
					}, 200, function() {
					});
					$(this).addClass("expanded");
					flashKV.kv2.setCondition("over",1100);
				}
			}
		},
		mouseleave : function() {
			if ( $(this).hasClass("expanded") ) {
				if ( !$(this).hasClass("open") ) {
					$(this).animate({
						"width" : "575px",
						"left" : "193px"
					}, 200);
					$(this).removeClass("expanded");
					flashKV.kv2.setCondition("collapse", 1100);
				}
			}
			$expand.hide();
		},
		click : function() {
			if ( clickable ) {
				clickable = false;
				if ( !$(this).hasClass("open") ) {
					textShow();
					$expand.hide();
					$section.eq(0).animate({
						"left" : "0px",
						"width" : "960px"
					}, {
						duration: 700,
						//easing: "easeOutExpo",
						complete : function() {
							$btnClose.fadeIn(50);
							expandable = false;
						}
					})
					.addClass("open");
					$section.eq(0).find(".image").animate({
						"left" : 0
					},{
						duration: 700
						//easing: "easeOutExpo"
					});
					flashReady = "expand";
					flashKV.kv2.setCondition("expand");
				} else {
					$btnClose.fadeOut(50);
					textHide();
					$expand.show();
					$section.eq(0)
						.animate({
							"width" : "575px",
							"left" : "193px"
						}, {
							duration: 700
							//easing: "easeOutExpo"
						})
						.removeClass("open");
					$section.eq(0).find(".image").animate({
						"left" : "-192px"
					}, {
						duration: 700
						//easing: "easeOutExpo"
					});
					flashReady = "collapse";
					flashKV.kv2.setCondition("collapse");

				}
			}
		}
	});

	function textShow() {

		$h4.eq(0).stop(true, true).fadeOut(150);
		$desc.eq(0).stop(true, true).fadeOut(150, function() {
			$h4.eq(1).stop(true, true).animate({
				"left" : "30px"
			}, {
				duration: 800,
				easing: "easeOutExpo"
			});

			$desc.eq(1).stop(true, true).animate({
				"left" : "30px"
			}, {
				duration: 1000,
				easing: "easeOutExpo"
			});

			$link.eq(0).stop(true, true).animate({
				"left" : "30px"
			}, {
				duration: 1200,
				easing: "easeOutExpo",
				complete : function() {
					clickable = true;
				}
			});

		});



	}

	function textHide() {

		$h4.eq(1).animate({
			"left" : "-800px"
		}, {
			duration: 700,
			easing: "easeOutExpo"
		});

		$desc.eq(1).animate({
			"left" : "-800px"
		}, {
			duration: 700,
			easing: "easeOutExpo"
		});

		$link.eq(0).animate({
			"left" : "-800px"
		}, {
			duration: 900,
			easing: "easeOutExpo",
			complete : function() {
				$h4.eq(0).fadeIn(150);
				$desc.eq(0).fadeIn(150);
				expandable = true;
				clickable = true;
			}
		});

	}

}

function tvAudioVideo() {

	var $section = $("#tvAudioVideo").find(".section");
	var $btnClose = $section.eq(0).find(".btnClose");
	var $h4 = $section.eq(0).find("h4");
	var $desc = $section.eq(0).find(".description");
	var $link = $section.eq(0).find(".link");
	var $learnMore = $("#tvAudioVideo").find("p.btnLearnMore");
	var clickable = true;
	var expandable = true;
	var $expand = $("#expandTooltip");

	$btnClose.find("a").click(function(e) {
		e.stopPropagation();
		$btnClose.fadeOut(50);
		textHide();
		$expand.show();
		$section.eq(0)
			.animate({
				"width" : "575px"
			}, {
				duration: 1100,
				easing: "easeOutExpo"
			})
			.removeClass("open");
		flashReady = "collapse";
		flashKV.kv3.setCondition("collapse");
		return false;
	});

	$section.eq(0).bind({
		mouseenter : function() {
			if ( !$(this).hasClass("open") ) {
				$expand.show();
			}
			if ( !$(this).hasClass("expanded") ) {
				if ( !$(this).hasClass("open") ) {
					$(this).stop(true, true).animate({
						"width" : "600px"
					}, 200, function() {
					});
					$(this).addClass("expanded");
					flashReady = "over";
					flashKV.kv3.setCondition("over");
				}
			}
		},
		mouseleave : function() {
			if ( $(this).hasClass("expanded") ) {
				if ( !$(this).hasClass("open") ) {
					$(this).animate({
						"width" : "575px"
					}, 200, function() {
					});
					$(this).removeClass("expanded");
					flashReady = "collapse";
					flashKV.kv3.setCondition("collapse");
				}
			}
			$expand.hide();
		},
		click : function(e) {
			if ( clickable ) {
				clickable = false;
				if ( !$(this).hasClass("open") ) {
					textShow();
					$expand.hide();
					$(this).animate({
						"width" : "960px"
					}, {
						duration: 1100,
						easing: "easeOutExpo",
						complete : function() {
							$btnClose.fadeIn(50);
							expandable = false;
						}
					})
					.addClass("open");
					flashReady = "expand";
					flashKV.kv3.setCondition("expand");
				} else {
					$btnClose.fadeOut(50);
					textHide();
					$expand.show();
					$section.eq(0)
						.animate({
							"width" : "575px"
						}, {
							duration: 1100,
							easing: "easeOutExpo"
						})
						.removeClass("open");
					flashReady = "collapse";
					flashKV.kv3.setCondition("collapse");
				}
			}
		}
	});

	function textShow() {

		$desc.eq(0).stop(true, true).fadeOut(150);

		$h4.eq(0).stop(true, true).fadeOut(150, function() {
			$h4.eq(1).stop(true, true).delay(150).animate({
				"left" : "30px"
			}, {
				duration: 1100,
				easing: "easeOutExpo"
			});

			$desc.eq(1).stop(true, true).animate({
				"left" : "30px"
			}, {
				duration: 1100,
				easing: "easeOutExpo",
				complete : function() {

				}
			});

			$link.stop(true, true).animate({
				"left" : "30px"
			}, {
				duration: 1100,
				easing: "easeOutExpo",
				complete : function() {
					clickable = true;
				}
			});

		});

	}

	function textHide() {

		$desc.eq(1).stop(true, true).animate({
			"left" : "-800px"
		},{
			duration: 700,
			easing: "easeOutExpo"
		});

		$link.stop(true, true).animate({
			"left" : "-800px"
		},{
			duration: 700,
			easing: "easeOutExpo"
		});

		$h4.eq(1).stop(true, true).animate({
			"left" : "-800px"
		}, {
			duration: 700,
			easing: "easeOutExpo",
			complete : function() {
				$desc.eq(0).fadeIn(350);
				$h4.eq(0).fadeIn(350, function() {
					expandable = true;
					clickable = true;
				});
			}
		});

	}

}


function cameraCamcorder() {

	var $section = $("#cameraCamcorder").find(".section");
	var $btnClose = $section.eq(0).find(".btnClose");
	var $h4 = $section.eq(0).find("h4");
	var $desc = $section.eq(0).find(".description");
	var $link = $section.eq(0).find(".link");
	var $learnMore = $("#cameraCamcorder").find("p.btnLearnMore");
	var expandable = true;
	var clickable = true;
	var $expand = $("#expandTooltip");

	$btnClose.find("a").click(function(e) {
		e.stopPropagation();
		$btnClose.fadeOut(50);
		textHide();
		$expand.show();
		$section.eq(0)
			.animate({
				"width" : "383px"
			}, {
				duration: 1100,
				easing: "easeOutExpo"
			})
			.removeClass("open");
		flashReady = "collapse";
		flashKV.kv4.setCondition("collapse");
		return false;
	});

	$section.eq(0).bind({
		mouseenter : function() {
			if ( !$(this).hasClass("open") ) {
				$expand.show();
			}
			if ( !$(this).hasClass("expanded") ) {
				if ( !$(this).hasClass("open") ) {
					$(this).stop(true, true).animate({
						"width" : "420px"
					}, 200, function() {
					});
					$(this).addClass("expanded");
					flashReady = "over";
					flashKV.kv4.setCondition("over");
				}
			}
		},
		mouseleave : function() {
			if ( $(this).hasClass("expanded") ) {
				if ( !$(this).hasClass("open") ) {
					$(this).animate({
						"width" : "383px"
					}, 200, function() {
					});
					$(this).removeClass("expanded");
					flashReady = "collapse";
					flashKV.kv4.setCondition("collapse");
				}
			}
			$expand.hide();
		},
		click : function(e) {
			if ( clickable ) {
				clickable = false;
				if ( !$(this).hasClass("open") ) {
					textShow();
					$expand.hide();
					$(this).animate({
						"width" : "960px"
					}, {
						duration: 1100,
						easing: "easeOutExpo",
						complete : function() {
							$btnClose.fadeIn(50);
							expandable = false;
						}
					})
					.addClass("open");
					flashReady = "expand";
					flashKV.kv4.setCondition("expand");
				} else {
					$btnClose.fadeOut(50);
					textHide();
					$expand.show();
					$section.eq(0)
						.animate({
							"width" : "383px"
						}, {
							duration: 1100,
							easing: "easeOutExpo"
						})
						.removeClass("open");
					flashReady = "collapse";
					flashKV.kv4.setCondition("collapse");
				}
			}
		}
	});

	function textShow() {

		$desc.eq(0).stop(true, true).animate({
			"left" : "-600px"
		}, 700);

		$h4.eq(0).stop(true, true).animate({
			"left" : "-600px"
		},500, function() {
			$h4.eq(1).stop(true, true).delay(150).animate({
				"left" : "30px"
			}, {
				duration: 1100,
				easing: "easeOutExpo"
			});

			$desc.eq(1).stop(true, true).animate({
				"left" : "30px"
			}, {
				duration: 1100,
				easing: "easeOutExpo",
				complete : function() {

				}
			});

			$link.stop(true, true).animate({
				"left" : "30px"
			}, {
				duration: 1100,
				easing: "easeOutExpo",
				complete : function() {
					clickable = true;
				}
			});

		});

	}

	function textHide() {

		$desc.eq(1).stop(true, true).animate({
			"left" : "-800px"
		},{
			duration: 1000,
			easing: "easeOutExpo"
		});

		$link.stop(true, true).animate({
			"left" : "-800px"
		},{
			duration: 1000,
			easing: "easeOutExpo"
		});

		$h4.eq(1).stop(true, true).animate({
			"left" : "-800px"
		}, {
			duration: 700,
			easing: "easeOutExpo",
			complete : function() {
				$desc.eq(0).stop(true, true).animate({
					"left" : "30px"
				}, 700);

				$h4.eq(0).stop(true, true).animate({
					"left" : "30px"
				},500, function() {
					expandable = true;
					clickable = true;
				});
			}

		});

	}
}

function notebooksDisplay() {

	var $section = $("#notebooksDisplay").find(".section");
	var $btnClose = $section.eq(0).find(".btnClose");
	var $h4 = $section.eq(0).find("h4");
	var $desc = $section.eq(0).find(".description");
	var $link = $section.eq(0).find(".link");
	var $learnMore = $("#notebooksDisplay").find("p.btnLearnMore");
	var expandable = true;
	var clickable = true;
	var $expand = $("#expandTooltip");

	$btnClose.find("a").click(function(e) {
		e.stopPropagation();
		$btnClose.fadeOut(50);
		textHide();
		$expand.show();
		$section.eq(0)
			.animate({
				"width" : "575px",
				"left" : "193px"
			}, {
				duration: 1100,
				easing: "easeOutExpo"
			})
			.removeClass("open");
		$section.eq(0).find(".image").animate({
			"left" : "-192px"
		}, {
			duration: 1000,
			easing: "easeOutExpo"
		});
		flashReady = "collapse";
		flashKV.kv5.setCondition("collapse");
		return false;
	});

	$section.eq(0).bind({
		mouseenter : function() {
			if ( !$(this).hasClass("open") ) {
				$expand.show();
			}
			if ( !$(this).hasClass("expanded") ) {
				if ( !$(this).hasClass("open") ) {
					$(this).stop(true, true).animate({
						"width" : "620px",
						"left" : "173px"
					}, 200, function() {
					});
					$(this).addClass("expanded");
					//flashKV.kv5.setCondition("over", 200);
				}
			}
		},
		mouseleave : function() {
			if ( $(this).hasClass("expanded") ) {
				if ( !$(this).hasClass("open") ) {
					$(this).animate({
						"width" : "575px",
						"left" : "193px"
					}, 200);
					$(this).removeClass("expanded");
					//flashKV.kv5.setCondition("collapse", 200);
				}
			}
			$expand.hide();
		},
		click : function() {
			if ( clickable ) {
				clickable = false;
				if ( !$(this).hasClass("open") ) {
					textShow();
					$expand.hide();
					$section.eq(0).animate({
						"left" : "0px",
						"width" : "960px"
					}, {
						duration: 1100,
						easing: "easeOutExpo",
						complete : function() {
							$btnClose.fadeIn(50);
							expandable = false;
						}
					})
					.addClass("open");
					$section.eq(0).find(".image").animate({
						"left" : 0
					},{
						duration: 1100,
						easing: "easeOutExpo"
					});
					flashReady = "expand";
					flashKV.kv5.setCondition("expand");
				} else {
					$btnClose.fadeOut(50);
					textHide();
					$expand.show();
					$section.eq(0)
						.animate({
							"width" : "575px",
							"left" : "193px"
						}, {
							duration: 1100,
							easing: "easeOutExpo"
						})
						.removeClass("open");
					$section.eq(0).find(".image").animate({
						"left" : "-192px"
					}, {
						duration: 1100,
						easing: "easeOutExpo"
					});
					flashReady = "collapse";
					flashKV.kv5.setCondition("collapse");

				}
			}
		}
	});

	function textShow() {

		$h4.eq(0).stop(true, true).fadeOut(150);
		$desc.eq(0).stop(true, true).fadeOut(150, function() {
			$h4.eq(1).stop(true, true).animate({
				"left" : "30px"
			}, {
				duration: 800,
				easing: "easeOutExpo"
			});

			$desc.eq(1).stop(true, true).animate({
				"left" : "30px"
			}, {
				duration: 1000,
				easing: "easeOutExpo"
			});

			$link.eq(0).stop(true, true).animate({
				"left" : "30px"
			}, {
				duration: 1200,
				easing: "easeOutExpo",
				complete : function() {
					clickable = true;
				}
			});

		});



	}

	function textHide() {

		$h4.eq(1).animate({
			"left" : "-800px"
		}, {
			duration: 700,
			easing: "easeOutExpo"
		});

		$desc.eq(1).animate({
			"left" : "-800px"
		}, {
			duration: 700,
			easing: "easeOutExpo"
		});

		$link.eq(0).animate({
			"left" : "-800px"
		}, {
			duration: 900,
			easing: "easeOutExpo",
			complete : function() {
				$h4.eq(0).fadeIn(150);
				$desc.eq(0).fadeIn(150);
				expandable = true;
				clickable = true;
			}
		});

	}

}


function homeAppliances() {

	var $section = $("#homeAppliances").find(".section");
	var $btnClose = $section.eq(0).find(".btnClose");
	var $h4 = $section.eq(0).find("h4");
	var $desc = $section.eq(0).find(".description");
	var $link = $section.eq(0).find(".link");
	var $learnMore = $("#homeAppliances").find("p.btnLearnMore");
	var expandable = true;
	var clickable = true;
	var $expand = $("#expandTooltip");

	$btnClose.find("a").click(function(e) {
		e.stopPropagation();
		$btnClose.fadeOut(50);
		textHide();
		$expand.show();
		$section.eq(0)
			.animate({
				"width" : "575px"
			}, {
				duration: 1100,
				easing: "easeOutExpo"
			})
			.removeClass("open");
		flashReady = "collapse";
		flashKV.kv6.setCondition("collapse");
		return false;
	});

	$section.eq(0).bind({
		mouseenter : function() {
			if ( !$(this).hasClass("open") ) {
				$expand.show();
			}
			if ( !$(this).hasClass("expanded") ) {
				if ( !$(this).hasClass("open") ) {
					$(this).stop(true, true).animate({
						"width" : "600px"
					}, 200, function() {
					});
					$(this).addClass("expanded");
					flashReady = "over";
					flashKV.kv6.setCondition("over");
				}
			}
		},
		mouseleave : function() {
			if ( $(this).hasClass("expanded") ) {
				if ( !$(this).hasClass("open") ) {
					$(this).animate({
						"width" : "575px"
					}, 200, function() {

					});
					$(this).removeClass("expanded");
					flashReady = "collapse";
					flashKV.kv6.setCondition("collapse");
				}
			}
			$expand.hide();
		},
		click : function(e) {
			if ( clickable ) {
				clickable = false;
				if ( !$(this).hasClass("open") ) {
					textShow();
					$expand.hide();
					$section.eq(0).animate({
						"width" : "960px"
					}, {
						duration: 1100,
						easing: "easeOutExpo",
						complete : function() {
							$btnClose.fadeIn(50);
							expandable = false;
						}
					})
					.addClass("open");
					flashReady = "expand";
					flashKV.kv6.setCondition("expand");
				} else {
					$btnClose.fadeOut(50);
					textHide();
					$expand.show();
					$section.eq(0)
						.animate({
							"width" : "575px"
						}, {
							duration: 1100,
							easing: "easeOutExpo"
						})
						.removeClass("open");
					flashReady = "collapse";
					flashKV.kv6.setCondition("collapse");
				}
			}
		}
	});

	function textShow() {

		$desc.eq(0).stop(true, true).fadeOut(150);

		$h4.eq(0).stop(true, true).fadeOut(150, function() {
			$h4.eq(1).stop(true, true).delay(150).animate({
				"left" : "30px"
			}, {
				duration: 1100,
				easing: "easeOutExpo"
			});

			$desc.eq(1).stop(true, true).animate({
				"left" : "30px"
			}, {
				duration: 1100,
				easing: "easeOutExpo",
				complete : function() {

				}
			});

			$link.stop(true, true).animate({
				"left" : "30px"
			}, {
				duration: 1100,
				easing: "easeOutExpo",
				complete : function() {
					clickable = true;
				}
			});

		});

	}

	function textHide() {

		$desc.eq(1).stop(true, true).animate({
			"left" : "-800px"
		},{
			duration: 700,
			easing: "easeOutExpo"
		});

		$link.stop(true, true).animate({
			"left" : "-800px"
		},{
			duration: 700,
			easing: "easeOutExpo"
		});

		$h4.eq(1).stop(true, true).animate({
			"left" : "-800px"
		}, {
			duration: 900,
			easing: "easeOutExpo",
			complete : function() {
				$desc.eq(0).fadeIn(350);
				$h4.eq(0).fadeIn(350);
				expandable = true;
				clickable = true;
			}
		});

	}
}


function indexTab() {

	var $tab = $("#indexTab");
	var $trigger = $tab.find("li");
	var $cont = $(".homeContent").children("div");

	var p = parameters();

	$cont.hide();

	if(p.brightcove) {
		$trigger.find("a.videos").addClass("activator").parent().addClass("activator");
		$($trigger.find("a.videos").attr("href")).show();
	}
	else {
		$trigger.eq(0).addClass("activator").find("a").addClass("activator");
		$cont.eq(0).show();
	}

	$trigger.each(function(i) {
		$(this).find("a").bind({
			click : function() {
				var $thisCont = $($(this).attr("href"));
				$trigger.each(function() {
					$(this).removeClass("activator");
					$(this).find("a").removeClass("activator");
				});
				$(this).addClass("activator");
				$(this).parent().addClass("activator");
				$cont.hide();
				$thisCont.fadeIn(250);

				switch($thisCont.attr('id')) {
					case 'twitter' :
						if($('#twitter .tweetArea li').length == 0) {
							var script = $("<script>", { "type" : "text/javascript", "src" : "http://twitter.com/statuses/user_timeline/"+twitterScreenName+".json?callback=twitterCallback&count=3"});
							script.appendTo($('#twitter .tweetArea'));
						}
						if($('#twitter .tweetArea iframe').length == 0) {
							tweetBoxRender();
						}
						break;
					case 'videos' :
						try{indexBC();} catch(e){};
						break;
					default:
						break;
				}
				if($thisCont.attr('id') != 'videos') $('#videos .bc').html('');
				return false;
			}
		});
	});

}

var twitterScreenName = 'samsungpolska';

function twitterInit() {
	$('#twitter .tweetArea').text('Ładuję…');
	$('#twitter .btnArea').html('<a href="#none" class="btnStyle tw" id="btnCTW"><span>Połącz się z serwisem <strong>Twitter</strong></span></a>');

	twttr.anywhere(function (T) {

		tweetBoxRender();

		twitterConnect(T);

		if(!isMobile) T('#twitter').hovercards();

		T.bind("authComplete", function (e, user) {
			twitterConnect(T);
		});

		T.bind("signOut", function (e) {
			twitterConnect(T);
		});

	});
}

function twitterConnect(T) {
	var currentUser, screenName, profileImage, profileImageTag;

	if (T.isConnected()) {
		currentUser = T.currentUser;
		screenName = currentUser.data('screen_name');
		profileImage = currentUser.data('profile_image_url');
		profileImageTag = "<img width='20' height='20' src='" + profileImage + "'/>";
		$('#twitter .btnArea').html(profileImageTag + " Logged in as " + screenName + " ( <a href='#none' onclick='twttr.anywhere.signOut();'>Sign out</a> )");
	} else {
		$('#twitter .btnArea').html('<a href="#none" class="btnStyle tw" id="btnCTW"><span>Połącz się z serwisem <strong>Twitter</strong></span></a>');
		$('#btnCTW').click(function () {
			s_control_click('events,eVar17', 'event15', 'event15,home:twitter', 'o', 'social media click');
			T.signIn();
			return false;
		});
	}
}

function tweetBoxRender() {
	twttr.anywhere(function (T) {
		$("#twitter .tweetBox").html('');
		T("#twitter .tweetBox").tweetBox({
			counter: false,
			width: 708,
			height: 80,
			label: '&nbsp;',
			defaultContent: '@'+twitterScreenName,
			onTweet : function(plaintext, html) {
				s_control_click('events,eVar17', 'event15', 'event15,home:twitter', 'o', 'social media click');
				alert('Twój wpis został dodany. Dziękujemy!');
				tweetBoxRender();
			}
		});
	});
}

function twitterCallback(twitters) {
	var statusHTML = [];

	for (var i=0; i<twitters.length; i++){
		var username = twitters[i].user.screen_name;
		var status = twitters[i].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
			return '<a href="'+url+'" target="_blank">'+url+'</a>';
		}).replace(/\B@([_a-z0-9]+)/ig, function(reply) {
			return  reply.charAt(0)+'<a href="http://twitter.com/'+reply.substring(1)+'" target="_blank">'+reply.substring(1)+'</a>';
		});
		statusHTML.push('<li' + ((i+1)==twitters.length?' class="last"':'') + '>'+status+'</li>');
	}
	$('#twitter .tweetArea').html('<ul>' + statusHTML.join('') + '</ul>');
}
