// JavaScript Document
ind_c = 0;

pic_id = new Array("se-coremethod","se-prospecting","se-clevel","se-negotiation");
a_id = new Array("gallery-coremethod","gallery-prospecting","gallery-sellingc-level","gallery-negotiation");

news_index=0;

cicle_num = 0;

var t;

var n;

var sendArr = new Array(0,0,0,0);

/*get key word focus*/
	
 function GetQueryString(name) 
      {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)","i");
			var x = document.referrer;	
            var r = x.substr(1).match(reg);
            if (r!=null) return unescape(r[2]); return null;
      } 
		
function CompareSearchKey()	{
			
			keyVal=""
			keyVal = GetQueryString("q");
			var strReplace = "+";
			if (keyVal!=null) {				
				keyVal = keyVal.replace(/\+/g," ");
			}
			if (keyVal==null) keyVal="";

			
var imgExist;

var imgArr = new Array("image1","image2","image3");

var image1 = new Array("web conferencing","online meeting","web meeting","desktop sharing","share desktop","file sharing","application sharing","webexmeeting","webex meeting center");

var image2 = new Array("webex mobile","webex for mobile","webex and mobiles","webex on mobile","webex mobile phone","webex iphone","webex ipad","webex smartphones","mobile video conferencing","mobile remote desktop software","webex mobile","mobile video conference","mobile desktop sharing","pc mobile software");

var image3 = new Array("video conferencing","video conference","webex video","video webex","high quality video","webcam video","Webex high quality video","high quality video conferencing","high quality video conference","high quality online video conference","high quality video conferences","Webex high quality video conferencing","Webex HQ video conferencing","Webex Meeting Center High Quality Video");

// negotiation
var image4 = new Array("webex for sales","webex sales tool","webex sales product","webex sales software","webex sales productivity tool","webex selling tool","webex selling software","webex sales presentations","webex sales application","webex sales meetings","sales with webex","sales productivity tool","sales increase productivity tools","sales productivity software","sales productivity tools for business","effective sales productivity tools","increase sales productivity","online sales presentation software","online selling presentation tool","remote sales presentation","deliver sales presentations","sales presentations over the web","online sales events","conduct sales events","host online sales events","online sales events for large groups","remote sales events online","easy online sales events","online sales event application","online sales event tool","online sales event software","online sales team meetings","hold sales team meetings online","online sales center application","online sales center tool","online sales center software");

//negotiation2
var image5 = new Array("webex for elearning","elearning with webex","webex elearning","web ex elearning","webx elearning","webex e-learning","try webex elearning","webex elearning trial","elearning software","education video conferencing","educational video conferencing","educational videoconferencing","education webcast","e learning","elearning provider","e learning software","elearning software","elearning software companies","software for e learning","software for elearning","free elearning software","download elearning software","elearning software trial","easy elearning software","effective elearning software","elearning software demonstration","affordable elearning software","interactive online training","online learning training","online training companies","online training system","web based training","web based training company","video conferencing for learning","video conferencing in education","best web based training","web based training development","web based training system");

//negotiation3
var image6 = new Array("WebEx support center","Webex remote support","Webex remote access","Webex for remote support","Webex for support","Webex customer support"," Webex helpdesk support ","support center","remote support","remote access","customer support software","helpdesk support software","remote support software");

//negotiation4
var image7 = new Array("WebEx for events","Webex online events","Webex webinars","Webex for webinar","Webex webinar","Webex for webinars","Webex for webcasts","Webex webcasts","WebEx for webcast","WebEx webcast","online events","webinars","webinar","webcasts","for webcast","webcast");

//negotiation5
var image8 = new Array("321654");

imgExist=0;

if(keyVal!="") {
	
	for(i=0;i<image1.length;i++){
		if(image1[i]==keyVal){
			imgExist=0;
			break;
		}	
	}
	for(i=0;i<image2.length;i++){
		if(image2[i]==keyVal){
			imgExist=1;
			break;
		}	
	}
	for(i=0;i<image3.length;i++){
		if(image3[i]==keyVal){
			imgExist=2;
			break;
		}	
	}
	for(i=0;i<image4.length;i++){
		if(image4[i]==keyVal){
			imgExist=3;
			break;
		}	
	}
	for(i=0;i<image5.length;i++){
		if(image5[i]==keyVal){
			imgExist=4;
			break;
		}	
	}
	for(i=0;i<image6.length;i++){
		if(image6[i]==keyVal){
			imgExist=5;
			break;
		}	
	}
	for(i=0;i<image7.length;i++){
		if(image7[i]==keyVal){
			imgExist=6;
			break;
		}	
	}
	for(i=0;i<image8.length;i++){
		if(image8[i]==keyVal){
			imgExist=7;
			break;
		}	
	}
	
}


return imgExist;		
			
}


/*end key word*/


function slideSwitch() {

	ind_n = ind_c + 1;
	if (ind_n == 4) ind_n = 0;
	
	$("#"+pic_id[ind_c]).fadeOut(500);
	$("#"+pic_id[ind_n]).fadeIn(500);
	$("#"+a_id[ind_c]).removeClass("gallery-current");
	$("#"+a_id[ind_n]).addClass("gallery-current");

	ind_c = ind_c + 1;
	if (ind_c == 4) ind_c = 0;
	
	cicle_num = cicle_num +1;
	if (cicle_num == 4){
		if (t)		clearInterval(t);
	}

}
/*The number of articles in the news ticker*/
var news_items = 3;
function newSwitch() {
		clearInterval(n);
		$("#news-ticker .news").eq(news_index).hide();
		if(news_index == news_items){news_index=0;}
		else {news_index = news_index+1;}
		$("#news-ticker .news").eq(news_index).show();
		n=setInterval( "newSwitch()", 5000 );
}

/*set cookie*/
function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
  {
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}

function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}
/*  ------------   */


$(function() {

	$("#tray").css("display", "block");
	
	//$(".current").css("opacity","1.0");
	
	$("#news-ticker .news:first").show();
	
	sales_ran=Math.floor(Math.random()*5);
	//alert(sales_ran);
	
	/*
	var username=getCookie("webex_type");
	if (username!=null && username!=""){
	  //alert(username);
	  sales_ran = username;
	}
	else {
		setCookie("webex_type",sales_ran,30);
	}
	*/

	
	keynum=CompareSearchKey(); 
	switch(keynum)
	{
		
		case 0:
				ind_c = 0;
				break;

		case 1:
				ind_c = 1;
				break;
		case 2:
				ind_c = 2;
				break;
		case 3: // negotiation
				ind_c = 3;
				sales_ran = 0;
				break;
		case 4: // negotiation2
				ind_c = 3;
				sales_ran = 1;
				break;
		case 5: // negotiation3
				ind_c = 3;
				sales_ran = 2;
				break;
		case 6: // negotiation4
				ind_c = 3;
				sales_ran = 3;
				break;
		case 7: // negotiation5
				ind_c = 3;
				sales_ran = 4;
				break;
		default:
				ind_c = 0;
				break;
	}
	
	if (sales_ran == 0) {  //show negotiation
		pic_id[3]="se-negotiation";
		a_id[3]="gallery-negotiation";
		$("#gallery-negotiation").css("display", "block");
		$("#gallery-negotiation2").css("display", "none");
		$("#gallery-negotiation3").css("display", "none");
		$("#gallery-negotiation4").css("display", "none");
		$("#gallery-negotiation5").css("display", "none");
	}
	else if (sales_ran == 1) { // show negotiation2
		pic_id[3]="se-negotiation2";
		a_id[3]="gallery-negotiation2";
		$("#gallery-negotiation").css("display", "none");
		$("#gallery-negotiation2").css("display", "block");
		$("#gallery-negotiation3").css("display", "none");
		$("#gallery-negotiation4").css("display", "none");
		$("#gallery-negotiation5").css("display", "none");
	}
	else if (sales_ran == 2) { // show negotiation3
		pic_id[3]="se-negotiation3";
		a_id[3]="gallery-negotiation3";
		$("#gallery-negotiation").css("display", "none");
		$("#gallery-negotiation2").css("display", "none");
		$("#gallery-negotiation3").css("display", "block");
		$("#gallery-negotiation4").css("display", "none");
		$("#gallery-negotiation5").css("display", "none");
	}
	else if (sales_ran == 3) { // show negotiation4
		pic_id[3]="se-negotiation4";
		a_id[3]="gallery-negotiation4";
		$("#gallery-negotiation").css("display", "none");
		$("#gallery-negotiation2").css("display", "none");
		$("#gallery-negotiation3").css("display", "none");
		$("#gallery-negotiation4").css("display", "block");
		$("#gallery-negotiation5").css("display", "none");
	}
	else if (sales_ran == 4) { // show negotiation5
		pic_id[3]="se-negotiation5";
		a_id[3]="gallery-negotiation5";
		$("#gallery-negotiation").css("display", "none");
		$("#gallery-negotiation2").css("display", "none");
		$("#gallery-negotiation3").css("display", "none");
		$("#gallery-negotiation4").css("display", "none");
		$("#gallery-negotiation5").css("display", "block");
	}

	
	$("#"+pic_id[ind_c]).fadeIn();
	$("#"+a_id[ind_c]).addClass("gallery-current");

	
	var b_v = navigator.appVersion;
	var IE6 = b_v.search(/MSIE 6/i) != -1;

	if (IE6)
	{
		DD_belatedPNG.fix('img, #tray, #news-ticker, #left-arrow, #right-arrow, #pod1, #pod2, #pod3');  
	} 
	
	
    n=setInterval( "newSwitch()", 5000 );
	

	
    t=setInterval( "slideSwitch()", 5000 );
	
	
	
	

	$("#gallery-coremethod").click( function() {
		if (t)		clearInterval(t);
		if (ind_c != 0){
			$("#"+pic_id[ind_c]).fadeOut(500);
			$("#"+pic_id[0]).fadeIn(500);
			$("#"+a_id[ind_c]).removeClass("gallery-current");
			$("#"+a_id[0]).addClass("gallery-current");
		}
		ind_c = 0;
		track_clicks('wx:us:hero:core-method:thumbnail_click','slideshow');

	});	
	
	$("#gallery-prospecting").click( function() {
		if (t)		clearInterval(t);
		if (ind_c != 1){
			$("#"+pic_id[ind_c]).fadeOut(500);
			$("#"+pic_id[1]).fadeIn(500);
			$("#"+a_id[ind_c]).removeClass("gallery-current");
			$("#"+a_id[1]).addClass("gallery-current");
		}
		ind_c = 1;
		track_clicks('wx:us:hero:prospecting:thumbnail_click','slideshow');

	});
		
	$("#gallery-sellingc-level").click( function() {
		if (t)		clearInterval(t);
		if (ind_c != 2){
			$("#"+pic_id[ind_c]).fadeOut(500);
			$("#"+pic_id[2]).fadeIn(500);
			$("#"+a_id[ind_c]).removeClass("gallery-current");
			$("#"+a_id[2]).addClass("gallery-current");
		}
		ind_c = 2;
		track_clicks('wx:us:hero:c-level:thumbnail_click','slideshow');

	});
	
		
	$("#gallery-negotiation").click( function() {
		if (t)		clearInterval(t);
		if (ind_c != 3){
			$("#"+pic_id[ind_c]).fadeOut(500);
			$("#"+pic_id[3]).fadeIn(500);
			$("#"+a_id[ind_c]).removeClass("gallery-current");
			$("#"+a_id[3]).addClass("gallery-current");
		}
		ind_c = 3;
		track_clicks('wx:us:hero:negotiation:thumbnail_click','slideshow');

	});
		
	$("#gallery-negotiation2").click( function() {
		if (t)		clearInterval(t);
		if (ind_c != 3){
			$("#"+pic_id[ind_c]).fadeOut(500);
			$("#"+pic_id[3]).fadeIn(500);
			$("#"+a_id[ind_c]).removeClass("gallery-current");
			$("#"+a_id[3]).addClass("gallery-current");
		}
		ind_c = 3;
		track_clicks('wx:us:hero:negotiation2:thumbnail_click','slideshow');

	});
	
	$("#gallery-negotiation3").click( function() {
		if (t)		clearInterval(t);
		if (ind_c != 3){
			$("#"+pic_id[ind_c]).fadeOut(500);
			$("#"+pic_id[3]).fadeIn(500);
			$("#"+a_id[ind_c]).removeClass("gallery-current");
			$("#"+a_id[3]).addClass("gallery-current");
		}
		ind_c = 3;
		track_clicks('wx:us:hero:negotiation3:thumbnail_click','slideshow');

	});	
		
	$("#gallery-negotiation4").click( function() {
		if (t)		clearInterval(t);
		if (ind_c != 3){
			$("#"+pic_id[ind_c]).fadeOut(500);
			$("#"+pic_id[3]).fadeIn(500);
			$("#"+a_id[ind_c]).removeClass("gallery-current");
			$("#"+a_id[3]).addClass("gallery-current");
		}
		ind_c = 3;
		track_clicks('wx:us:hero:negotiation4:thumbnail_click','slideshow');

	});
		
	$("#gallery-negotiation5").click( function() {
		if (t)		clearInterval(t);
		if (ind_c != 3){
			$("#"+pic_id[ind_c]).fadeOut(500);
			$("#"+pic_id[3]).fadeIn(500);
			$("#"+a_id[ind_c]).removeClass("gallery-current");
			$("#"+a_id[3]).addClass("gallery-current");
		}
		ind_c = 3;
		track_clicks('wx:us:hero:enterprise:thumbnail_click','slideshow');

	});

	$("#left-arrow").click( function(event) {
		event.preventDefault();
		$("#news-ticker .news").eq(news_index).hide();
		if(news_index == 0){news_index=news_items;}
		else {news_index = news_index-1;}
		$("#news-ticker .news").eq(news_index).show();
	});
	
	$("#right-arrow").click( function(event) {
		event.preventDefault();
		$("#news-ticker .news").eq(news_index).hide();
		if(news_index == news_items){news_index=0;}
		else {news_index = news_index+1;}
		$("#news-ticker .news").eq(news_index).show();
	});

	$("#coremethod_button").click( function() {
			track_clicks('wx:us:hero:together:buy_now','slideshow');
	});
	$("#Together_FT").click( function() {
			track_clicks('wx:us:hero:together:try_it_free','slideshow');
	});
	$("#prospecting_button").click( function() {
			track_clicks('wx:us:hero:prospecting:get_the_app','slideshow');
	});
	$("#ipad_ft").click( function() {
			track_clicks('wx:us:hero:prospecting:try_webex_free','slideshow');
	});
	$("#ipad_lm").click( function() {
			track_clicks('wx:us:hero:prospecting:learn_more','slideshow');
	});
	$("#c-level_button").click( function() {
			track_clicks('wx:us:hero:hq-video:buy_now','slideshow');
	});
	$("#video_ft").click( function() {
			track_clicks('wx:us:hero:hq-video:try_it_free','slideshow');
	});
	$("#video_lm").click( function() {
			track_clicks('wx:us:hero:hq-video:learn_more','slideshow');
	});
	$("#negotiation_button").click( function() {
			track_clicks('wx:us:hero:negotiation:learn_more','slideshow');
	});
	$("#negotiation_button2").click( function() {
			track_clicks('wx:us:hero:negotiation2:learn_more','slideshow');
	});
	$("#negotiation_button3").click( function() {
			track_clicks('wx:us:hero:negotiation3:learn_more','slideshow');
	});
	$("#negotiation_button4").click( function() {
			track_clicks('wx:us:hero:negotiation4:learn_more','slideshow');
	});
	$("#negotiation_button5").click( function() {
			track_clicks('wx:us:hero:negotiation5:learn_more','slideshow');
	});
	
});





// function track custom clicks to site catalyst.
/*
* link_name => link name of custom link; will be shown in site catalyst  reporting
* linkcategory => category to determine which eVars/eProps to store
*  choices: slideshow
*/
function track_clicks(link_name, linkcategory){
	var LinkName = 'undefined';
				   
	if(typeof link_name != 'undefined')
	{
		LinkName= link_name;
	}
				   
	if(typeof linkcategory != 'undefined')
	{
		switch(linkcategory){
			case 'slideshow':
			s.linkTrackVars="prop30,eVar30";
			s.eVar30 = link_name;
			s.prop30 = link_name;  
			break;
			default:       
		}
	}
	//s.sa('webextest');
	void s.tl(this, 'o', LinkName);
}

function Get_Cookie(name) {
    var start = document.cookie.indexOf(name+"=");
    var len = start+name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
    if (start == -1) return null;
    var end = document.cookie.indexOf(";",len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
}

function Set_Cookie(name,value,expires,path,domain,secure) {
domain = '.webex.com';
path = '/';
    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") + 
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");
}

function Delete_Cookie(name,path,domain) {
domain = '.webex.com';
path = '/';
    if (Get_Cookie(name)) document.cookie = name + "=" +
        ( (path) ? ";path=" + path : "") +
        ( (domain) ? ";domain=" + domain : "") +
        ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
