﻿var lastProposalButtonClick;

var Site = {
    isOneOpened:null,
    lastOpened:null,
    currentBarOpen:null,
    currentBarOpenPositionX:null,
    isBarOpening:null,
    isTabOpening:null,
    currentTabFx:null,
    currentTabFx2:null,
    currentTabFx3:null,
    isTabClosing:null,
    LightBox:null,
    tempValue:null,
    
	init:function(){
	

//var szNormal = 94, szSmall  = 50, szFull   = 265;
// 
//var kwicks = $$("#kwicks .kwick");
//var fx = new Fx.Elements(kwicks, {wait: false, duration: 300, transition: Fx.Transitions.Back.easeOut});
//kwicks.each(function(kwick, i) {
//	kwick.addEvent("mouseenter", function(event) {
//		var o = {};
//		o[i] = {width: [kwick.getStyle("width").toInt(), szFull]}
//		kwicks.each(function(other, j) {
//			if(i != j) {
//				var w = other.getStyle("width").toInt();
//				if(w != szSmall) o[j] = {width: [w, szSmall]};
//			}
//		});
//		fx.start(o);
//	});
//});
// 
//$("kwicks").addEvent("mouseleave", function(event) {
//	var o = {};
//	kwicks.each(function(kwick, i) {
//		o[i] = {width: [kwick.getStyle("width").toInt(), szNormal]}
//	});
//	fx.start(o);
//})
// 
//			
	
        var topTabs = $("wrapper").getElement(".benefitsBox").getElements(".item");
        var barItems = $("wrapper").getElements(".barItem");
        var requestMeetingButtons = $("wrapper").getElements(".requestMeeting");
        
        Site.LightBox = new Lightbox($("lightBoxForm"));
        
        requestMeetingButtons.each (function(rmb,i){
            rmb.addEvent('click',function(e){
				switch(rmb.title) {
					case 'top':
						lastProposalButtonClick = 'top';
						track('/business2008/proposal/button/');
						break;
					case 'bottom':
						lastProposalButtonClick = 'bottom';
						track('/business2008/bottom/proposal/button/');
						break;
				}
                $("campaign").value=rmb.id;
                Site.LightBox.show();
            });
        });
        
        $("lightBoxForm").getElements(".txt").each(function(el,ind){
			el.addEvent('click',function(e){el.value = "";});
            el.addEvent('blur',function(e){if(el.value==""){el.value = el.title;}});
        });
        
        $("wrapper").getElement(".benefitsBox").getElements(".extraLine").each (function(itemB,i){
            itemB.addEvent('mouseenter',function(e){
                if (itemB.hasClass("left"))
				    var fx3 = new Fx.Style(itemB.getParent().getElement(".corner-left"),'height',{duration:100}).start(3);    
				else
				    var fx3 = new Fx.Style(itemB.getParent().getElement(".corner-right"),'height',{duration:100}).start(3);
				var fx2 = new Fx.Style(itemB.getParent().getElement("#"+itemB.id.substring(0,itemB.id.length-1)).getElement(".bottomLayer"),'height',{duration:200}).start(9);				
            });
        });
        
        topTabs.each (function(item,i){
			item.addEvent('click',function(e){
				switch(item.id) {
					case '1':
						track('/business2008/box/healthy/button/');
						break;
					case '2':
						track('/business2008/box/working/button/');
						break;
					case '3':
						track('/business2008/box/clients/button/');
						break;
					case '4':
						track('/business2008/box/success/button/');
						break;
					case '5':
						track('/business2008/box/sell/button/');
						break;
					case '6':
						track('/business2008/box/special/button/');
						break;
					default:
						break;
				}
			    if (Site.isTabOpening && Site.isTabOpening == 1) {
			        if (Site.currentTabFx != null) Site.currentTabFx.cancel();
			        if (Site.currentTabFx2 != null) Site.currentTabFx2.cancel();
			        if (Site.currentTabFx3 != null) Site.currentTabFx3.cancel();
			    }
		        if ((Site.isTabOpening && Site.isTabOpening == 1) || (Site.isOneOpened && Site.isOneOpened == 1))
			    {
			        topTabs.each (function(itemA,i){
			            if (itemA.id != item.id && (itemA.getParent().getElement("#"+itemA.id+"A").getStyle("height").toInt() > 0 || itemA.getElement(".bottomLayer").getStyle("height").toInt() > 0)){
			                Site._closeItem(itemA);
			                if (itemA.hasClass("hover"))
			                    itemA.removeClass("hover");
			            }
			        });
			    }	
		        Site.isTabOpening = 1;
			    if ((Site.lastOpened && Site.lastOpened.hasClass("hover")) || (Site.lastOpened && Site.lastOpened.id==item.id))
			    {
			        topTabs.each (function(itemA,i){
			            if (itemA.id != item.id && itemA.getParent().getElement("#"+itemA.id+"A").getStyle("height").toInt() > 0)
			                Site._closeItem(itemA);
			        });
			    }
			    Site.lastOpened = item;
				item.addClass("hover");
				(function(){
				    if (item.getParent().getElement("#"+item.id+"A").hasClass("left"))
				        var fx3 = new Fx.Style(item.getParent().getElement(".corner-left"),'height',{duration:100}).start(3);
				    else
				        var fx3 = new Fx.Style(item.getParent().getElement(".corner-right"),'height',{duration:100}).start(3);
    				Site.currentTabFx3 = fx3;
				    var fx2 = new Fx.Style(item.getElement(".bottomLayer"),'height',{duration:200}).start(9).chain(function(){
				        Site.currentTabFx2 = fx2;
				        var fx = new Fx.Style(item.getParent().getElement("#"+item.id+"A"),'height',{duration:400}).start(70).chain(function(){
				            Site.currentTabFx = fx;
    			            Site.isOneOpened = 1;	
    			            Site.isTabOpening = 0;    
				        });				
				    });
				}).delay(50);
			});
		}); 
		
		barItems.each (function(barItem,i){
		    barItem.addEvent('click',function(e){
		        if (Site.isBarOpening && Site.isBarOpening == 1){
                    if (Site.currentBarOpen)
	                    Site._closeBar(Site.currentBarOpen);                    
                    barItems.each (function(barItemC,i){
                        if (barItemC.id != barItem.id && barItemC.getElement(".barDescription").getStyle("width").toInt() > 0){
		                    var barsFx = new Fx.Style($("businessBarsBox"),'margin-right',{duration:400}).start(0).chain(function(){
                                var barItemFx2 = new Fx.Style(barItemC.getElement(".barDescription"),'width',{duration:600}).start(0)		                
		                    });
		                    (function(){
                            barItemFx3 = new Fx.Style(barItemC,'margin-right',{duration:400}).start(3);
                            }).delay(400);
                        }
                    });		        
		        }
		        if (Site.currentBarOpen && Site.currentBarOpen.id == barItem.id)
		            return false;	            
		        e=new Event(e);
                e.stop();
		        Site.isBarOpening = 1;
		        var posToMoveTo = barItem.getCoordinates().left-$('businessBarsBox').getCoordinates().left;
		        if (Site.currentBarOpen != null)
		            Site._closeBar(Site.currentBarOpen,Site.currentBarOpenPositionX);
                Site.currentBarOpenPositionX = posToMoveTo;		            
		        Site.currentBarOpen = barItem;
		        barItem.setStyles({"position":"absolute","left":posToMoveTo});
		        barItemFx = new Fx.Elements(barItem,{duration: 600,transition: Fx.Transitions.Sine.easeOut,wait: false});
		        var obj = {};
		        var objn = {};		        
		        obj[0] = {"left":436,"margin-right":3};
		        barItem.addClass("hover");
		        objn[0] = {"opacity":1};
		        barItemFx5 = new Fx.Elements(barItem.getElement(".hoverBg"),{wait: 400, transition: Fx.Transitions.linear,wait:false});
		        barItemFx5.start(objn);
		        barItemFx.start(obj).chain(function(){
		            var barItemFx2 = new Fx.Style(barItem.getElement(".barDescription"),'width',{duration:600}).start(263).chain(function(){
		                Site.isBarOpening = 0;
		            }); 
		        });
		        var barsFx = new Fx.Style($("businessBarsBox"),'margin-right',{duration:400}).start(61);
		        (function(){
		            barItems.each (function(barItemEl,i){
		                if ((Site.currentBarOpen && barItemEl.id != Site.currentBarOpen.id) || !Site.currentBarOpen)
		                {
		                    var fx2 = new Fx.Style(barItemEl,'margin-right',{duration:400}).start(-61);
		                }
		            });
		        }).delay(600);
				
		    });
		});
		
		$("wrapper").getElement(".rightPane").addEvent('mouseleave',function(e){
            var waitTime = 0;
            if (Site.currentBarOpen){
	            Site._closeBar(Site.currentBarOpen); 
	            waitTime = 600; 
	        }
            (function(){
                barItems.each (function(barItemC,i){
        		    var barsFx = new Fx.Style($("businessBarsBox"),'margin-right',{duration:400}).start(0).chain(function(){
                        var barItemFx2 = new Fx.Style(barItemC.getElement(".barDescription"),'width',{duration:600}).start(0)		                
                    });
	                (function(){
                        barItemFx3 = new Fx.Style(barItemC,'margin-right',{duration:400}).start(3).chain(function(){
                            Site.currentBarOpen = null;
                        });
                    }).delay(600);
                });
             }).delay(waitTime);
		});
		
		$("wrapper").getElement(".rightPane").addEvent('mouseleave',function(e){
            var waitTime = 0;
            if (Site.currentBarOpen){
	            Site._closeBar(Site.currentBarOpen); 
	            waitTime = 600; 
	        }
            (function(){
                barItems.each (function(barItemC,i){
        		    var barsFx = new Fx.Style($("businessBarsBox"),'margin-right',{duration:400}).start(0).chain(function(){
                        var barItemFx2 = new Fx.Style(barItemC.getElement(".barDescription"),'width',{duration:600}).start(0)		                
                    });
	                (function(){
                        barItemFx3 = new Fx.Style(barItemC,'margin-right',{duration:400}).start(3).chain(function(){
                            Site.currentBarOpen = null;
                        });
                    }).delay(600);
                });
             }).delay(waitTime);
		});
				
//		$("businessBarsBoxWrapper").addEvent('mouseleave',function(e){
//            var waitTime = 0;
//            if (Site.currentBarOpen){
//	            Site._closeBar(Site.currentBarOpen); 
//	            waitTime = 600; 
//	        }
//            (function(){
//                barItems.each (function(barItemC,i){
//        		    var barsFx = new Fx.Style($("businessBarsBox"),'margin-right',{duration:400}).start(0).chain(function(){
//                        var barItemFx2 = new Fx.Style(barItemC.getElement(".barDescription"),'width',{duration:600}).start(0)		                
//                    });
//	                (function(){
//                        barItemFx3 = new Fx.Style(barItemC,'margin-right',{duration:400}).start(3).chain(function(){
//                            Site.currentBarOpen = null;
//                        });
//                    }).delay(600);
//                });
//             }).delay(waitTime);
//		});
				
//		$("wrapper").getElement(".benefitsBox").addEvent('mouseleave',function(e){
//		    if (Site.lastOpened && Site.lastOpened.hasClass("hover"))
//		    {
//		        topTabs.each (function(itemA,i){
//		            if (itemA.getParent().getElement("#"+itemA.id+"A").getStyle("height").toInt() > 0)
//		                Site._closeItem(itemA);
//		        });		    
//		        //Site._closeItem(Site.lastOpened);
//		    }
//		});	
//		$("wrapper").getElement(".leftPane").addEvent('mouseenter',function(e){
//		    if (Site.lastOpened && Site.lastOpened.hasClass("hover"))
//		    {
//		        topTabs.each (function(itemA,i){
//		            if (itemA.getParent().getElement("#"+itemA.id+"A").getStyle("height").toInt() > 0)
//		                Site._closeItem(itemA);
//		        });		    
//		        //Site._closeItem(Site.lastOpened);
//		    }
//		});	
		$("wrapper").getElement(".leftPane").addEvent('mouseleave',function(e){
		    if (Site.lastOpened && Site.lastOpened.hasClass("hover"))
		    {
		        topTabs.each (function(itemA,i){
		            if (itemA.getParent().getElement("#"+itemA.id+"A").getStyle("height").toInt() > 0)
		                Site._closeItem(itemA);
		        });		    
		        //Site._closeItem(Site.lastOpened);
		    }
		});				
//		$("wrapper").getElement(".rightPane").addEvent('mouseenter',function(e){
//		    if (Site.lastOpened && Site.lastOpened.hasClass("hover"))
//		    {
//		        topTabs.each (function(itemA,i){
//		            if (itemA.getParent().getElement("#"+itemA.id+"A").getStyle("height").toInt() > 0)
//		                Site._closeItem(itemA);
//		        });		    
//		        //Site._closeItem(Site.lastOpened);
//		    }
//		});						
    },
    _closeItem:function(item){
        Site.isTabClosing = 1;
		item.removeClass("hover");
		var fx = new Fx.Style(item.getParent().getElement("#"+item.id+"A"),'height',{duration:400}).start(0);
	    Site.isTabClosing = 0;
	    var fx2 = new Fx.Style(item.getElement(".bottomLayer"),'height',{duration:200}).start(0);
	    if (item.getParent().getElement("#"+item.id+"A").hasClass("left"))
	        var fx3 = new Fx.Style(item.getParent().getElement(".corner-left"),'height',{duration:100}).start(0);
	    else
	        var fx3 = new Fx.Style(item.getParent().getElement(".corner-right"),'height',{duration:100}).start(0);			
    },
    _closeBar:function(item,pos){
        var barItemFx5 = new Fx.Elements(item.getElement(".hoverBg"),{wait: 400, transition: Fx.Transitions.linear,wait:false});
        var objn = {};
        objn[0] = {"opacity":0};
        barItemFx5.start(objn);
        var barItemFx2 = new Fx.Style(item.getElement(".barDescription"),'width',{duration:400}).start(0).chain(function(){
            item.removeClass("hover");
            if (pos){
		        var barItemFx6 = new Fx.Style(item,'left',{duration:500}).start(pos).chain(function(){
                    item.setStyles({"position":"relative","left":"auto","margin-right":3});
                });
            }
            else
                item.setStyles({"position":"relative","left":"auto","margin-right":3});
        });
    }
};

$DL(
	function () {
		Site.init();
	}
);


function sendForm(siteUrl){
    document.getElementById("resultOK").style.display="none";
    document.getElementById("resultFAILED").style.display="none";

    if(DOM.Get("contactPersonA").value=="" ||DOM.Get("companyA").value=="" || DOM.Get("phoneA").value=="" || DOM.Get("emailA").value==""){
        alert("נא למלא את כל הפרטים");
        return;
    }
    
    track('/business2008/bottom/join/button/');

    var xReq=Browser.XML.HTTP();

    var postData="name="+encodeURI(DOM.Get("contactPersonA").value).replace("&","")+"\
    &company="+encodeURI(DOM.Get("companyA").value).replace("&","")+"\
    &phone="+encodeURI(DOM.Get("phoneA").value).replace("&","")+"\
    &numEmployees="+encodeURI(DOM.Get("numEmployeesA").value).replace("&","")+"\
    &email="+encodeURI(DOM.Get("emailA").value).replace("&","")+"\
    &ref="+encodeURI(DOM.Get("refA").value).replace("&","")+"\
    &campaign="+encodeURI(DOM.Get("campaignA").value).replace("&","")


	var ajaxSiteUrl = siteUrl;
	if (window.location.toString().indexOf('http://www.') == -1 && siteUrl.indexOf('http://www.') != -1) {
		ajaxSiteUrl = siteUrl.replace('http://www.', 'http://');
	}
	
    xReq.open("POST",ajaxSiteUrl+"/Business2008/formSend2.asp",true);

    xReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

    xReq.onreadystatechange=function(){
        if(xReq.readyState==4){
            if(xReq.responseText=="OK") {
				document.getElementById("resultOK").style.display="block";
				document.getElementById("joinFormA").style.display="none";
				track('/Business2008/detailssent')
            }
            else {document.getElementById("resultFAILED").style.display="block";
            alert(xReq.responseText);}
            
        }
    };


    xReq.send(postData);
}


function sendLightBoxForm(siteUrl){
    document.getElementById("resultOK-LB").style.display="none";
    document.getElementById("resultFAILED-LB").style.display="none";

    if(DOM.Get("fullName").value==DOM.Get("fullName").title ||DOM.Get("company").value==DOM.Get("company").title || DOM.Get("phone").value==DOM.Get("phone").value.title || DOM.Get("numEmployees").value==DOM.Get("numEmployees").title || DOM.Get("email").value==DOM.Get("email").title){
        alert("נא למלא את כל הפרטים");
        return;
    }
    
    trackLightboxSend();

    var xReq=Browser.XML.HTTP();

    var postData="fullName="+encodeURI(DOM.Get("fullName").value).replace("&","")+"\
    &company="+encodeURI(DOM.Get("company").value).replace("&","")+"\
    &phone="+encodeURI(DOM.Get("phone").value).replace("&","")+"\
    &numEmployees="+encodeURI(DOM.Get("numEmployees").value).replace("&","")+"\
    &email="+encodeURI(DOM.Get("email").value).replace("&","")+"\
    &ref="+encodeURI(DOM.Get("ref").value).replace("&","")+"\
    &campaign="+encodeURI(DOM.Get("campaign").value).replace("&","")

	var ajaxSiteUrl = siteUrl;
	if (window.location.toString().indexOf('http://www.') == -1 && siteUrl.indexOf('http://www.') != -1) {
		ajaxSiteUrl = siteUrl.replace('http://www.', 'http://');
	}
	
    xReq.open("POST",ajaxSiteUrl+"/Business2008/formSend.asp",true);

    xReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

    xReq.onreadystatechange = function() {
        if (xReq.readyState == 4) {
            if (xReq.responseText == "OK") {
                document.getElementById("resultOK-LB").style.display = "block";
                document.getElementById("joinForm").style.display = "none";
                track('/Business2008/detailssent');
            }
            else {
                document.getElementById("resultFAILED-LB").style.display = "block";
                alert(xReq.responseText);
            }

        }
    };


    xReq.send(postData);
}

function trackCloseButton() {
	if (lastProposalButtonClick == 'top') {
		track('/business2008/proposal/closed/button/');
	}
	else {
		track('/business2008/bottom/proposal/closed/button/');
	}
}

function trackLightboxSend() {
	if (lastProposalButtonClick == 'top') {
		track('/business2008/proposal/sent/button/');
	}
	else {
		track('/business2008/bottom/proposal/sent/button/');
	}
}

function CreateFlash(container,id,src,width,height,extraHtml){//handles any arguments beside these
    var objStr="",embedStr="",parSplit;
    for (i=6; i<CreateFlash.arguments.length; i++){
        parSplit=CreateFlash.arguments[i].split("=");
        objStr+="<param name='"+parSplit[0]+"' value='"+parSplit[1]+"' />"
        embedStr+=" "+parSplit[0]+"='"+parSplit[1]+"' "
    }
    var el=document.getElementById(container);
    el.innerHTML+="\
    <object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' \
        width='"+width+"' height='"+height+"' id='"+id+"'>\
	    <param name='movie' value='"+src+"' />\
	    "+objStr+" \
	    <embed type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' \
	    src='"+src+"' width='"+width+"' height='"+height+"'\
	    name='"+id+"' "+embedStr+" />\
    </object>\
     "+ (extraHtml?extraHtml:"")+"\
    ";
}