﻿//הוספת הבאנרים
 $(window).load(function () {
       $.ajax({
             type: "POST",
             contentType: "application/json; charset=utf-8",
             url: "../Services/Service.asmx/GetAdRotatorCategory",
             data:"{}",
             dataType: "json",
             success: function(results) {
                 $(results).each(function(){
                      if(this==null || this.CssClass== null|| this.CssClass.length==0) return;
                      var placeOfBanner=  $('.'+this.CssClass);
                      if(placeOfBanner.length>0)
                      {

                             $.ajax({
                                 type: "POST",
                                 contentType: "application/json; charset=utf-8",
                                 url: "../Services/Service.asmx/GetAdRotator",
                                 data:"{AdRotatorCategoryId:'" +this.AdRotatorCategoryId+ "',CountRecord:'" + placeOfBanner.length+"',ContentPageId:'" + PageId + "'}",
                                 dataType: "json",
                                 success: function(banners) {                                 
                               
                                            $(banners).each(function(i){
                                                    var  _dynamicTarget = (this.OpenInNewWindow)?'_blank':'_self';
                                                    
                                                    if(isSwf(this.FileUrl))
                                                    {
                                                            $(placeOfBanner[i]).media({ 
                                                            width:     this.Width, 
                                                            height:    this.Height, 
                                                            autoplay:  true, 
                                                            src:       root +'Data/' +this.FileUrl,
                                                            //attrs:     { attr1:  'attrValue1',  attr2:  'attrValue2' },  // object/embed attrs 
                                                            params:    { dynamicUrl: root+'Handler/Banner.ashx?id='+ this.AdRotatorId  , dynamicTarget: _dynamicTarget },
                                                            flashvars: { dynamicUrl: root+'Handler/Banner.ashx?id='+ this.AdRotatorId , dynamicTarget: _dynamicTarget }, // object params/embed attrs 
                                                            caption:   false // supress caption text 
                                                        }); 
                                                    }
                                                    else
                                                    {
                                                        if(this.FileUrl)//קיימת תמונה
                                                        {
                                                            var myAnchor = document.createElement("a");
                                                            var myImg = document.createElement("img");
                                                            $(myImg).attr({src:root +'Data/' +this.FileUrl,width:this.Width, height:this.Height}).appendTo(myAnchor);
                                                            $(myAnchor).attr({href: root+'Handler/Banner.ashx?id='+ this.AdRotatorId, target:_dynamicTarget}).appendTo(placeOfBanner[i]);
                                                        }

                                                    }
                                            });
                                            
                                            
           
                                   
                                  
                                 }

                          });
                          
                          
                          
                          
                      }
                 });
              
             }

      });
 
 
 
 
 
 

 

});
