// JavaScript Document
//--------------------------------------------------------------------------------------------------------------------------
function en2fr (str){
		var en = new Array('0','1','2','3','4','5','6','7','8','9', '3', '5', '0', '2', '1', '2', '6', '4');
  	    var fa = new Array('۰','۱','۲','۳','۴','۵','۶','۷','۸','۹','۳','۵', '۰', '۲', '۱', '۲', '۶', '۴');
    	var output = str
		for (ii=0; ii<34; ii++) {
			output = String(output);
			output = output.replace(en[ii], fa[ii]);
		}
		return output;
}
//-----
ImageTab = 1;
	 var headline_count;
	 var headline_interval;
	 var current_headline = 0;
	 var old_headline = 0;
(function($) {
	if(!document.defaultView || !document.defaultView.getComputedStyle){ // IE6-IE8
		var oldCurCSS = jQuery.curCSS;
		jQuery.curCSS = function(elem, name, force){
			if(name === 'background-position'){
				name = 'backgroundPosition';
			}
			if(name !== 'backgroundPosition' || !elem.currentStyle || elem.currentStyle[ name ]){
				return oldCurCSS.apply(this, arguments);
			}
			var style = elem.style;
			if ( !force && style && style[ name ] ){
				return style[ name ];
			}
			return oldCurCSS(elem, 'backgroundPositionX', force) +' '+ oldCurCSS(elem, 'backgroundPositionY', force);
		};
	}
	
	var oldAnim = $.fn.animate;
	$.fn.animate = function(prop){
		if('background-position' in prop){
			prop.backgroundPosition = prop['background-position'];
			delete prop['background-position'];
		}
		if('backgroundPosition' in prop){
			prop.backgroundPosition = '('+ prop.backgroundPosition;
		}
		return oldAnim.apply(this, arguments);
	};
	
	function toArray(strg){
		strg = strg.replace(/left|top/g,'0px');
		strg = strg.replace(/right|bottom/g,'100%');
		strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
		var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
		return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
	}
	
	$.fx.step. backgroundPosition = function(fx) {
		if (!fx.bgPosReady) {
			var start = $.curCSS(fx.elem,'backgroundPosition');
			
			if(!start){//FF2 no inline-style fallback
				start = '0px 0px';
			}
			
			start = toArray(start);
			
			fx.start = [start[0],start[2]];
			
			var end = toArray(fx.options.curAnim.backgroundPosition);
			fx.end = [end[0],end[2]];
			
			fx.unit = [end[1],end[3]];
			fx.bgPosReady = true;
		}
		//return;
		var nowPosX = [];
		nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
		nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];           
		fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

	};
})(jQuery);
var set = 'en'
$(document).ready(function() { 
	//LoadLanguage();
	ddsmoothmenu.init({mainmenuid: "smoothmenu1", orientation: 'v',	classname: 'ddsmoothmenu-v',contentsource: "markup"})
	//----------- create image tab
	strphoto = "";
	strphotobtn =""
	for (var iphoto=0; iphoto< PhotoTab.length; iphoto++) {
		strphoto += "<a style='background:url("+(PhotoTab[iphoto][1])+")' class='ImageTabImge' title='"+(PhotoTab[iphoto][0])+"' "//+(PhotoTab[iphoto][2])+"</div>"
		strphoto +=  "href='"+(PhotoTab[iphoto][2])+"' "
		strphoto +="></a>"
		strphotobtn += '<a href="'+(PhotoTab[iphoto][2])+'" class="TabPicBtn"><h1>'+(iphoto+1)+'</h1></a>'
	}//
	
	$(".TabPage_001").html(strphoto);
	$(".IMGTbtnP").html(strphotobtn);
	$('.TabPicBtn h1').fadeTo('fast', 0);
	$('.TabPicBtn:last-child h1').fadeTo('fast', 1);
	$('.TabPage_001 a').css('display', 'none');//last-child
	$('.TabPage_001 a:last-child').fadeIn('fast',function() { if ($.browser.msie) {this.style.removeAttribute('filter');} });
	//--------------
	//----------- create Movie tab
	strMovie = "";
	strMoviebtn =""
	for (var iMovie=0; iMovie< MovieTab.length; iMovie++) {
		strMovie += "<a style='background:url("+(MovieTab[iMovie][1])+")' class='ImageTabMovie' title='"+(MovieTab[iMovie][0])+"' "//+(PhotoTab[iphoto][2])+"</div>"
		strMovie +=  "href='"+(MovieTab[iMovie][2])+"' "
		strMovie +="></a>"
		strMoviebtn += '<a href="'+(MovieTab[iMovie][2])+'" class="TabMovBtn"><h1>'+(iMovie+1)+'</h1></a>'
	}//
	
	$(".TabPage_002").html(strMovie);
	$(".IMGTbtnM").html(strMoviebtn);
	$('.TabMovBtn h1').fadeTo('fast', 0);
	$('.TabMovBtn:last-child h1').fadeTo('fast', 1);
	$('.TabPage_002 a').css('display', 'none');//last-child
	$('.TabPage_002 a:last-child').fadeIn('fast',function() { if ($.browser.msie) {this.style.removeAttribute('filter');} });
	//--------------
	//----------- create News List
	strNews = "";
	strNewsbtn =""
	for (var iNews=0; iNews< TabContentNews.length; iNews++) {
		strNewsbtn += '<a href="'+TabContentNews[iNews][3]+'" >'+TabContentNews[iNews][0]+'</a>'
	}//
	$(".ContentTabPageNewsListOver").html(strNewsbtn);
	$('.ContentTabPageNews h1').html(TabContentNews[0][1]);
	$('.ContentTabPageNews h3').html(TabContentNews[0][2]);
	$('.ContentTabPageNews a').attr("href", TabContentNews[0][3]);
	$('.ContentTabPageNewsListOver a:eq(0)').css('color','#eab245');
	//--------------
	//----------- create Gozaresh List
	strGozaresh = "";
	strGozareshbtn =""
	for (var iGozaresh=0; iGozaresh< TabContentGozaresh.length; iGozaresh++) {
		strGozareshbtn += '<a href="'+TabContentGozaresh[iGozaresh][3]+'" >'+TabContentGozaresh[iGozaresh][0]+'</a>'
	}//
	$(".ContentTabPageGozareshListOver").html(strGozareshbtn);
	$('.ContentTabPageGozaresh h1').html(TabContentGozaresh[0][1]);
	$('.ContentTabPageGozaresh h3').html(TabContentGozaresh[0][2]);
	$('.ContentTabPageGozaresh a').attr("href", TabContentGozaresh[0][3]);
	$('.ContentTabPageGozareshListOver a:eq(0)').css('color','#eab245');
	//--------------
	//----------- create Goftego List
	strGoftego = "";
	strGoftegobtn =""
	for (var iGoftego=0; iGoftego< TabContentGoftego.length; iGoftego++) {
		strGoftegobtn += '<a href="'+TabContentGoftego[iGoftego][3]+'" >'+TabContentGoftego[iGoftego][0]+'</a>'
	}//
	$(".ContentTabPageGoftegoListOver").html(strGoftegobtn);
	$('.ContentTabPageGoftego h1').html(TabContentGoftego[0][1]);
	$('.ContentTabPageGoftego h3').html(TabContentGoftego[0][2]);
	$('.ContentTabPageGoftego a').attr("href", TabContentGoftego[0][3]);
	$('.ContentTabPageGoftegoListOver a:eq(0)').css('color','#eab245');
	//--------------
	$('.ImageTabP' ).bind({
		click: function() {
			if (ImageTab != 1) {
				$('.ImageTabBtn').css ('background-position','left top');
				$(this).css ('cursor','default');
				$('.ImageTabM').css ('cursor','pointer');
				ImageTab =1;
				$('.Tab_002').fadeOut('slow', function() {
					$('.Tab_001').fadeIn('slow',function() { if ($.browser.msie) {this.style.removeAttribute('filter');} });
				});
			}
			
			
		},
		mouseenter: function() {
			if (ImageTab != 1) {
				$('.ImageTabBtn').css ('background-position','right bottom');
			}
		},
		mouseleave: function() {
			if (ImageTab != 1) {
				$('.ImageTabBtn').css ('background-position','left bottom');
			}
			
		}							
	});
	$('.ImageTabM' ).bind({
		click: function() {
			if (ImageTab != 2) {
				$('.ImageTabBtn').css ('background-position','left bottom');
				$(this).css ('cursor','default');
				$('.ImageTabP').css ('cursor','pointer');
				ImageTab =2;
				$('.Tab_001').fadeOut('slow', function() {
					$('.Tab_002').fadeIn('slow',function() { if ($.browser.msie) {this.style.removeAttribute('filter');} });
				});
				
				
			}
			
			
		},
		mouseenter: function() {
			if (ImageTab != 2) {
				$('.ImageTabBtn').css ('background-position','right top');
			}
		},
		mouseleave: function() {
			if (ImageTab != 2) {
				$('.ImageTabBtn').css ('background-position','left top');
			}
			
		}			//TabPicBtn	 ImageTabImg			
	});
	$('.ImageTabImge' ).bind({
		
		mouseenter: function() {
			$(this).stop()
			$(this).fadeTo('fast', 0.6);
		},
		mouseleave: function() {
			$(this).stop()
			$(this).fadeTo('fast', 1);
			
		}			//TabPicBtn	 ImageTabImg	IMGTbtnP		
	});
	$('.IMGTbtnP a' ).bind({
		click: function() {
			//alert($('.IMGTbtnP a').index(this));
			$('.TabPage_001 a').fadeOut('fast');
			$('.TabPage_001 a:eq('+$('.IMGTbtnP a').index(this)+')').fadeIn('fast',function() { if ($.browser.msie) {this.style.removeAttribute('filter');} });
			$('.TabPicBtn h1').fadeTo('fast', 0);
			$(this).find('h1').fadeTo('fast', 1);
			return false;
		}
			
	})
	$('.ImageTabMovie' ).bind({
		
		mouseenter: function() {
			$(this).stop()
			$(this).fadeTo('fast', 0.6);
		},
		mouseleave: function() {
			$(this).stop()
			$(this).fadeTo('fast', 1);
			
		}			//TabPicBtn	 ImageTabImg	IMGTbtnP		
	});
	$('.IMGTbtnM a' ).bind({
		click: function() {
			//alert($('.IMGTbtnP a').index(this));
			$('.TabPage_002 a').fadeOut('fast');
			$('.TabPage_002 a:eq('+$('.IMGTbtnM a').index(this)+')').fadeIn('slow',function() { if ($.browser.msie) {this.style.removeAttribute('filter');} });
			$('.TabMovBtn h1').fadeTo('fast', 0);
			$(this).find('h1').fadeTo('fast', 1);
			return false;
		}
			
	})
	$('.ContentTabBtn a' ).bind({
		click: function() {
			//alert($('.IMGTbtnP a').index(this));
			$('.ContentTabTabs div.ctab').fadeOut('fast')
				
				$('.ContentTabTabs div.ctab:eq('+$('.ContentTabBtn a').index(this)+')').fadeIn('slow', function(){if ($.browser.msie){this.style.removeAttribute('filter');}});
			
			
			
			//$('.TabMovBtn h1').fadeTo('fast', 0);
			//$(this).find('h1').fadeTo('fast', 1);
			if ($('.ContentTabBtn a').index(this) == 0) {$('.ContentTabBtn').css('background-position','bottom right');}
			if ($('.ContentTabBtn a').index(this) == 1) {$('.ContentTabBtn').css('background-position','center right');}
			if ($('.ContentTabBtn a').index(this) == 2) {$('.ContentTabBtn').css('background-position','top right');}
			
			
			
			return false;
		}
			
	})//
	$('.ContentTabPageNewsListOver, .ContentTabPageGozareshListOver, .ContentTabPageGoftegoListOver' ).css( {backgroundPosition: "0 0"} )
	
	$('.ContentTabPageNewsListOver a' ).bind({
		
		click: function() {
			pos = ($('.ContentTabPageNewsListOver a').index(this))*26
			
			//$(this).parent().stop().animate({backgroundPosition:"(0 "+pos+"px)"}, {duration:500});
			$(this).parent().css('backgroundPosition',"0px "+pos+"px")
			$('.ContentTabPageNewsListOver a').css('color','')
			$(this).css('color','#eab245');
										  
				$('.ContentTabPageNews h1').html(TabContentNews[$('.ContentTabPageNewsListOver a').index(this)][1]);
				$('.ContentTabPageNews h3').html(TabContentNews[$('.ContentTabPageNewsListOver a').index(this)][2]);
				$('.ContentTabPageNews a').attr("href", TabContentNews[$('.ContentTabPageNewsListOver a').index(this)][3])
				//$('.ContentTabPageNews').fadeTo('fast',1, function() {if ($.browser.msie){this.style.removeAttribute('filter');}});
			//});
			return false
		}		//TabPicBtn	 ImageTabImg	IMGTbtnP		//FooterLogo
		
		
	});
	$('.ContentTabPageGozareshListOver a' ).bind({
		
		click: function() {
			pos = ($('.ContentTabPageGozareshListOver a').index(this))*26
			
			//$(this).parent().stop().animate({backgroundPosition:"(0 "+pos+"px)"},{duration:500});
			$(this).parent().css('backgroundPosition',"0px "+pos+"px")
			$('.ContentTabPageGozareshListOver a').css('color','')
			$(this).css('color','#eab245');
										  
				$('.ContentTabPageGozaresh h1').html(TabContentGozaresh[$('.ContentTabPageGozareshListOver a').index(this)][1]);
				$('.ContentTabPageGozaresh h3').html(TabContentGozaresh[$('.ContentTabPageGozareshListOver a').index(this)][2]);
				$('.ContentTabPageGozaresh a').attr("href", TabContentGozaresh[$('.ContentTabPageGozareshListOver a').index(this)][3])
				//$('.ContentTabPageNews').fadeTo('fast',1, function() {if ($.browser.msie){this.style.removeAttribute('filter');}});
			//});
			return false;
		}		//TabPicBtn	 ImageTabImg	IMGTbtnP		//FooterLogo
		
		
	});
	$('.ContentTabPageGoftegoListOver a' ).bind({
		
		click: function() {
			pos = ($('.ContentTabPageGoftegoListOver a').index(this))*26
			
			//$(this).parent().stop().animate({backgroundPosition:"(0px "+pos+"px)"}, {duration:500});
			$(this).parent().css('backgroundPosition',"0px "+pos+"px")
			$('.ContentTabPageGoftegoListOver a').css('color','')
			$(this).css('color','#eab245');
										  
				$('.ContentTabPageGoftego h1').html(TabContentGoftego[$('.ContentTabPageGoftegoListOver a').index(this)][1]);
				$('.ContentTabPageGoftego h3').html(TabContentGoftego[$('.ContentTabPageGoftegoListOver a').index(this)][2]);
				$('.ContentTabPageGoftego a').attr("href", TabContentGoftego[$('.ContentTabPageGoftegoListOver a').index(this)][3])
				//$('.ContentTabPageNews').fadeTo('fast',1, function() {if ($.browser.msie){this.style.removeAttribute('filter');}});
			//});
			return false;
		}		//TabPicBtn	 ImageTabImg	IMGTbtnP		//FooterLogo
		
		
	});
	$('.FooterLogo a').fadeTo('fast', 0.6);
	$('.FooterLogo a' ).bind({
		
		mouseenter: function() {
			$(this).stop()
			$(this).fadeTo('fast', 1);
		},
		mouseleave: function() {
			$(this).stop()
			$(this).fadeTo('fast', 0.6);
			
		}			//TabPicBtn	 ImageTabImg	IMGTbtnP		
	});

//---------------- feed

	headline_count = $("div.headline").size();
   $(".headline:eq("+current_headline+")").css('top','0px');
  
   headline_interval = setInterval(headline_rotate,5000); //time in milliseconds
   $('#NewsFeed').hover(function() {
     clearInterval(headline_interval);
	 
   }, function() {
     headline_interval = setInterval(headline_rotate,1500); //time in milliseconds
     //headline_rotate();
	
   });


})
//----------- News Feed
function newsfeed() {
	for (i = 0; i< newsfeedarray.length; i++) {
		if (newsfeedarray[i][1] != "") { 
			document.write("<div id='newsfeedItem"+i+"' class='headline'>"+en2fr((i+1)+".")+" <a href='"+newsfeedarray[i][1]+"'>"+en2fr(newsfeedarray[i][0])+"</a></div>");
		} else { 
			document.write("<div id='newsfeedItem"+i+"' class='headline'>"+en2fr((i+1)+".")+" <span>"+en2fr(newsfeedarray[i][0])+"</span></div>");
		}
	}

}
function headline_rotate() {
     current_headline = (old_headline + 1) % headline_count; 
     $("div.headline:eq(" + old_headline + ")").animate({top: -30},"slow", function() {
   		$(this).css('top','30px');
   	 });
     $("div.headline:eq(" + current_headline + ")").show().animate({top: 0},"slow");  
     old_headline = current_headline;
   
   
 }
