﻿

$DL(
	function(){
		if(screen.width<=800){
			$(document.documentElement).setStyles({'overflow-x':'hidden'});	
			document.documentElement.scrollRight=50;
		}		
		if(Config.IsHomePage){
			BrandHp.Init();
		}
		else BrandManu.Init();				
		
		$$(".view-more").each(function(item){
			item.setStyles({opacity:.7});
		});
		//Progress.Init();
		if($("products-list")){
			var next=$("products-list").getElement(".next");			
			
			if(next){
				next.setStyles({opacity:.7});
				next.addEvent("mouseenter",function(){
				next.setStyles({opacity:1});
				});
				next.addEvent("mouseleave",function(){
					next.setStyles({opacity:.7});
				});
			}
			
			var prev=$("products-list").getElement(".prev");
			if(prev){
				prev.setStyles({opacity:.7});						
							
				prev.addEvent("mouseenter",function(){
					prev.setStyles({opacity:1});
				});
				prev.addEvent("mouseleave",function(){
					prev.setStyles({opacity:.7});
				});
			}	
		}
	}
);

var Config={
	SiteUrl:null,
	UploadPath:null,
	IsHomePage:null
};

var BrandManu={	
	Init: function(){		
		$$("#brandlist .list li.item").each(function(li,index){			
			li.setOpacity(1);
			if(typeof brandName!="undefined"){
				if(li.id==brandName) li.setOpacity(1);
				else this.CreateOver(li, index)
			}
			else this.CreateOver(li, index)
		}, this);
	},
	CreateOver: function(el, i){		
		var fx = new Fx.Styles(el, {'duration': 200, wait: false});		
		el.addEvent("mouseenter",function(){			
			fx.start({opacity: 1});			
		});
		el.addEvent("mouseleave",function(){			
			fx.start({opacity: .4});			
		});
	}
};

function hideContents() {
	BrandHp.InProgress = true;
}

function revealContents() {
	BrandHp.InProgress = false;
}

var BrandHp={
	Preview:null,	
	Last:null,
	LastSlideFx:null,
	InProgress:false,
	Init: function(){
		BrandHp.MainPromo=$("default").getElement(".BrandHp-preview");		
		BrandHp.MainPromo.setStyles({opacity: 0});
		BrandHp.MainPromo.show();
		$("default").addEvent("mouseleave",function(){
			if(BrandHp.LastSlideFx){				
				BrandHp.LastSlideFx.start({right: -470});
				BrandHp.Last.fade.start({opacity: .5});
				BrandHp.LastSlideFx=null;
				BrandHp.Last=null;				
				//TODO set logo opacity
			}
		});
		var fx = new Fx.Styles(BrandHp.MainPromo, {duration: 1500,transition: Fx.Transitions.linear});
		fx.start({opacity:1});
		$$("#BrandHp-list .list li.item").each(function(el,index){
			el.setOpacity(.5);
			var fadeFx = new Fx.Styles(el, {'duration': 200, wait: false});
			el.fade=fadeFx;
			$("brand_"+el.id).getFirst().setStyles({right:-470});
			$("brand_"+el.id).show();
			this.CreateOver(el, index)
		}, this);
	},
	CreateOver: function(el, i){
		el.addEvent("mouseenter",function(e){
			e = new Event(e).stop();

			// create an effext only if it's not created yet
			if (!el.slide) el.slide=new Fx.Styles($("brand_"+el.id).getFirst(), {
				duration: 1500,
				transition: Fx.Transitions.Quart.easeOut,
				wait: false
			});

			if(BrandHp.Last==el) return;
			if(BrandHp.Last){				
				BrandHp.Last.fade.start({opacity: .5});
			}
			el.fade.start({opacity: 1});
			BrandHp.Show(el);
			BrandHp.LastFadeFx=el.fade;
			BrandHp.Last=el;
		});
	},
	Show:function(el){		
		if(this.LastSlideFx) {
			this.LastSlideFx.start({right: -470});
		}
		el.slide.addEvent("onStart",function(){			
			BrandHp.InProgress=true;
		});
		el.slide.addEvent("onComplete",function(){			
			BrandHp.InProgress=false;
		});
		//el.setStyles({"z-index":3000});
		//alert(el.getStyle("z-index"));
		el.slide.start({right: 197});
		this.LastSlideFx=el.slide;
	}
};
var Progress={
	El:null,
	Fx:null,
	Init:function(){
		this.El=$("body").getElement(".progress");
		if(this.El){
			this.El.setStyles({opacity:.7});			
			this.Fx = new Fx.Styles(this.El, {"duration": 500, wait: false,transition: Fx.Transitions.Quart.easeOut});		
		}		
	},
	Show:function(){		
		if(this.Fx) Progress.Fx.start({height: 30});
	},
	Hide:function(){
		if(this.Fx) Progress.Fx.start.delay(1000,this.Fx,{height: 0});
	}
}

var Resources={
	RegisterCssFile:function(href){
		var headID = document.head;
		var cssNode = document.createElement("link");
		cssNode.type = "text/css";
		cssNode.rel = "stylesheet";
		cssNode.href = href;	
		headID.appendChild(cssNode);
	}
};
   function Add2Favorites(){
            var title = "יניר IT | Yanir-IT - www.Yanir-IT.co.il";
            var url = 'http://www.Yanir-It.com';
            if (window.sidebar){
                // Mozilla Firefox Bookmark
                window.sidebar.addPanel(title, url,"");}
            else if( window.external ){
                // IE Favorite
                window.external.AddFavorite(url, title);}}


