interstatialOK=false;

function expandCollapse(cmd_type) { 

	var direction = (cmd_type == 'open')? 1 : 2;
	
	var heightCur = (cmd_type == 'open')? parseInt(heightsize):heightSizeClose;
	
	if(document.getElementById) {
		divs = document.getElementById('topads');
		if (divs){
			if (cmd_type == 'open'){
//				divs.style.overflow = 'hidden';
				slideStart('topads', heightCur, direction);										
			}else if (cmd_type == 'close'){
//				divs.style.overflow = 'hidden';	
				slideStart('topads', heightCur, direction);										
			}
		}			
	}
}
// slider start
var StepPx = 1;  // adým baþý pixel
var StepMs = 10; // mili seconds
var t = 1;
var isSliding = false;

function slideStart(objID, toHeight, direction){
 if(isSliding) return;
 slideObj(objID, toHeight, direction);
}

function slideObj(objID, toHeight, direction){						    			    
	isSliding = true;
	var obj = document.getElementById(objID);				
	var curHeight = parseInt(obj.style.height);
	if(direction==1){
	if(curHeight>=toHeight){ isSliding=false; t=1; return;}
		obj.style.height = (curHeight + fn(t)*StepPx) + "px";
	}else{
	if(curHeight<=toHeight){ isSliding=false; t=1; return; }
		obj.style.height = (curHeight - fn(t)*StepPx) + "px";				
	}
	t++;
	setTimeout("slideObj('" + objID + "'," + toHeight + "," + direction + ")", StepMs);
}		

function fn(x){			 			    
return x;
}	
// slider end

function bannerbug(obj, islem) { 
	var nAgt = navigator.userAgent;
	if (nAgt.indexOf("MSIE")==-1){
		if(document.getElementById) {
			if (islem == 'open') {
				divs = document.getElementById(obj);
				//if (divs.style.visibility)
				divs.style.visibility = '';
			}
			if (islem == 'close') {
				divs = document.getElementById(obj);		 
				//if (divs.style.visibility)
				divs.style.visibility = 'collapse';
			}	
		}
	}
}

function _utf8_encode (string){
	string = string.replace(/\r\n/g,"\n");
    var utftext = "";

    for (var n = 0; n < string.length; n++) {

        var c = string.charCodeAt(n);

        if (c < 128) {
            utftext += String.fromCharCode(c);
        }
        else if((c > 127) && (c < 2048)) {
            utftext += String.fromCharCode((c >> 6) | 192);
            utftext += String.fromCharCode((c & 63) | 128);
        }
        else {
            utftext += String.fromCharCode((c >> 12) | 224);
            utftext += String.fromCharCode(((c >> 6) & 63) | 128);
            utftext += String.fromCharCode((c & 63) | 128);
        }

    }

    return utftext;
}

var setMargin = {
	offsetLeft: 0,
	marginLeft: 0,
	originalLeft: 0,
	page: '',
	ad: '',
	first: false,
	opened: false,
	show: function(){
		this.ad = document.getElementById('ad770');
		this.ad.style.display = '';
		this.ad.innerHTML = "<object id='ad770flash' style='z-index:469;' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' width='770' height='770'><param name='wmode' value='transparent'><param name='allowScriptAccess' value='always'><param name='movie' value='http://reklam5.mynet.com/reklam/renault/renault_megane_hp_sidekick.swf?clickTAG=http://servad.mynet.com/admynet/adredir.asp?ciid=46104%26url=http://ads.omdadget.com/adserver/adx/goto2.aspx?pbk=4138-4574-1277'><param name='quality' value='high'><embed name='ad770flash' id='ad770flash' style='position:z-index:469;' allowScriptAccess='always'  src='http://reklam5.mynet.com/reklam/renault/renault_megane_hp_sidekick.swf?clickTAG=http://servad.mynet.com/admynet/adredir.asp?ciid=46104%26url=http://ads.omdadget.com/adserver/adx/goto2.aspx?pbk=4138-4574-1277' wmode='transparent' quality=high pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width='770' height='770' swLiveConnect='true' scale='exactfit'></embed></object>";		
	},
	open: function(){
		if(this.opened == false){
			this.opened = true;
			this.page = document.getElementById('page');
			this.marginLeft = this.page.offsetLeft;
			this.originalLeft = this.marginLeft;
			this.ad.style.width = this.marginLeft + 'px';		
			var bannerWidth = 770;
			var tempWidth = 1000 - bannerWidth;
			this.offsetLeft = -1 * (1000 - this.marginLeft - tempWidth + 5);
			this.set(50,1);
		}
	},
	close: function(){
		if(this.opened == true){
			this.opened = false;
			this.page.style.marginLeft = this.originalLeft + 'px';
			this.ad.style.display = 'none';
			this.ad.innerHTML = '';
		}
	},
	set: function(coef,time){
	    if(this.marginLeft > this.offsetLeft){
	        this.page.style.marginLeft = this.marginLeft + 'px';
			if(this.first == false){
				this.ad.style.width = (this.originalLeft - 1) + 'px';
				this.first = true;
			} else {
				this.ad.style.width = (parseInt(this.ad.style.width.substring(0,3)) + coef) + 'px';
			}
	        this.marginLeft = this.marginLeft - coef;
	        window.setTimeout(function(){
	            setMargin.set(coef,time);
	        },time);
	    } else {
			this.page.style.marginLeft = this.offsetLeft + 'px';
			this.ad.style.width = '770px';
		}
	}
};

function _lc (element,category) {
	var getLink = element.href;
	window.location.href = "http://www.mynet.com/lc/lchome.aspx?c=" + category + "&url=" + escape(getLink);
	//window.location.href = getLink;
}
function _mynetaramaUtf8(form){
	var q = encodeURIComponent(form.q.value.replace('/',''));
	if(q == ''){
		window.location.href = 'http://arama.mynet.com';
		return false;
	}
	var gurl = '?cx=partner-pub-5464020032963120%3Aww4q6j-259k&cof=FORID%3A10&ie=UTF-8&q=';
	window.location.href= 'http://arama.mynet.com/web/'+q+'/1/'+gurl+q+'&utm_source=mynet&utm_medium=www&utm_campaign=home_arama_form';
	return false;
}	
var interstatialOK = false;
var homepageBar = 1;

var util = {
	setCookie: function(name, value, dakika, path, domain, secure){

		if(value.length > 4000)	return false;
		if(dakika !== 0 ){
			var d=new Date();
			d.setTime(d.getTime()+(dakika*60*1000));  	
			var expires="; expires="+d.toGMTString();  
		}else{
			var expires = "";
		}
		var path = path ? 	  ";path="+path:';path=/';
		var domain = domain ? ";domain="+domain:'';
		var secure = secure ? ";secure="+secure:'';
		document.cookie = name+"="+value+expires+path+domain+secure; 
	},
	getCookie: function (name) {
	    var dc = document.cookie;
	    var prefix = name + "=";
	    var begin = dc.indexOf("; " + prefix);
	    if (begin == -1) {
	        begin = dc.indexOf(prefix);
	        if (begin != 0) return null;
	    } else {
	        begin += 2;
	    }
	    var end = document.cookie.indexOf(";", begin);
	    if (end == -1) {
	        end = dc.length;
	    }
	    return unescape(dc.substring(begin + prefix.length, end));
	},
	json: function(source){
		var newelem = document.createElement("script");
		newelem.setAttribute("language","javascript");
		newelem.setAttribute("type","text\/javascript");
		newelem.setAttribute("onload","jQuery(this).remove()");
		newelem.setAttribute("src",source);
		document.getElementsByTagName("head")[0].appendChild(newelem);
		delete newelem;
	},
	json2string: function(jsonobj){
		var stringed = '{';
		for(i in jsonobj){
		    stringed = stringed + '"' + i + '"' + ':' + '"' + escape(jsonobj[i]) + '"' + ',';
		}
		stringed = stringed + '}';
		stringed = stringed.replace(',}','}');
		return stringed;
	},
	string2json: function(str){
		return eval("(" + str + ")");
	},
	xor: function (a,b) {
	  return ( a || b ) && !( a && b );
	},
	addEvent:function(element,olay,fonksiyon){
	    if (window.addEventListener != null) { // Firefox,Safari
	        olay = olay.substr(2);
	        element.addEventListener(olay,fonksiyon,false);
		}else{
	        element.attachEvent (olay,fonksiyon);
	    }
	}
};


function MynetHavaDurumu (response) {
	havadurumu.jsonresponse = response;
	havadurumu.cookie_set();
	havadurumu.set();
}

var havadurumu = {
	jsonresponse: '',
	url: 'http://havadurumu.mynet.com/city/json/',
	init: function(){
		var favcities_tmp = util.getCookie('favCitiesTmpNew');
		var favcities =  util.getCookie('favCities');
		if(favcities_tmp && (favcities == favcities_tmp.split("#")[0] || (!favcities && favcities_tmp.split("#")[0] == "default"))){
			
			this.jsonresponse = util.string2json(favcities_tmp.split("#")[1]);
			this.set();	
		} else {
			if(favcities){
				var favCity = favcities.split("|")[0];
			}
			if(favCity){
				util.json(this.url + '?' + favCity);
			} else {
				util.json(this.url);
			}
		}
	},
	set: function(){
		jQuery('.myLinkHavaDurumu').attr('href','http://havadurumu.mynet.com'+this.jsonresponse.url+'?utm_source=mynet&utm_medium=www&utm_campaign=home_havadurumu_header');
		jQuery('.myLinkHavaDurumu').html('<strong>'+this.jsonresponse.city+'</strong> <span>'+parseInt(this.jsonresponse.lowTemp)+'°C / '+parseInt(this.jsonresponse.highTemp)+'°C</span>');		
		jQuery('#havadurumuImg').html('<img src="http://img3.mynet.com.tr/myh/havadurumu/'+this.jsonresponse.icon+'.gif" alt="Hava Durumu"/>');
	},
	cookie_set: function(){
		var favcities = util.getCookie('favCities');
		if(!favcities){
			favcities = "default";
		}
		var cookieval = favcities + '#' + util.json2string(this.jsonresponse);
		util.setCookie('favCitiesTmpNew',cookieval);
	}	
};

var favori = {
    title:document.title,
    url:document.location.href,
    ekle:function(){
        if (window.sidebar) {
            window.sidebar.addPanel(this.title, this.url,false);
        } else if( window.external ) {
            window.external.AddFavorite(this.url, this.title);
        }else if(window.opera && window.print) {
            return true;
        }
    },
    anaSayfa : function(){
        if ( window.external ) {
            document.body.style.behavior='url(#default#homepage)';
            document.body.setHomePage(this.url);
        }
    }
};

function popupsoz(url){
	var yenipencere = null;
	yenipencere=window.open('','yenipencere','width=470,height=275,status=no,toolbar=no,menubar=no,directories=no,location=no,scrollbars=no,resizable=no,alwaysRaised=no,screenX=20,screenY=5,titlebar=yes,z-lock=yes,left=' + (screen.width - 470) / 2 + ',top=' + (screen.height - 275) / 2);
	if(yenipencere != null){
		if(yenipencere.opener == null){
			yenipencere.opener = self;
		}
		yenipencere.location.href=url;
		yenipencere.focus();
	}
}

function clearInput(obj,text){
	if(obj.value == text){
		obj.value = '';
	}
}

var astroloji = {
	url: 'http://astroloji.ivillage.mynet.com/fal/gunluk/',
	signs: Array('.','koc','boga','ikizler','yengec','aslan','basak','terazi','akrep','yay','oglak','kova','balik'),
	init: function (sign_id){
		with(this){
			if(sign_id != 0){
				document.location.href = url + signs[sign_id];
			} 
		}
	}
};

var searchSinema = {
	default_url:"http://sinema.mynet.com/arama/",
	urls:{
						"seanslar":"http://sinema.mynet.com/seans?utm_source=mynet&utm_medium=www&utm_campaign=home_sinema_keyword",
						"vizyondakiler":"http://sinema.mynet.com/vizyon?utm_source=mynet&utm_medium=www&utm_campaign=home_sinema_keyword"
						},
	urlEncode:function(str) {
					key = new Array('ð','ü','þ','ö','ç','ý',' ');
					needle = new Array('%C4%9F','%C3%BC','%C5%9F','%C3%B6','%C3%A7','%C4%B1','+');

					for (i = 0; i<key.length; i++) {
						var re = new RegExp(key[i], "g");
						str = str.replace(re, needle[i]);
					}

					return str;
	},
	returnSearchOptions:function(keyword){
		keyword = keyword.toLowerCase().replace(",","").replace(" ","_");
		if(this.urls[keyword]){
			return this.urls[keyword];
		} else {
			return false;
		}
	},
	init:function(){
		var keyword = document.getElementById('sinemaKeyword').value;
		if(keyword.length < 3){
			alert("Lütfen aramak için en az 3 harf giriniz");
			return false;
		}
		var url = this.returnSearchOptions(keyword);
		if(url){
			document.location.href = url;
		} else {
			document.location.href = this.default_url + keyword + '?utm_source=mynet&utm_medium=www&utm_campaign=home_sinema_search';
		}
	}
};

var searchFesmekan = {
	default_url:"http://fesmekan.mynet.com/istanbul/mekanlar/?q=",
	urls:{
						"barlar":"http://fesmekan.mynet.com/istanbul/mekanlar/bar",
						"cafeler":"http://fesmekan.mynet.com/istanbul/mekanlar/cafe",
						"restaurantlar":"http://fesmekan.mynet.com/istanbul/mekanlar/restaurant",
						"alisveris_merkezi":"http://fesmekan.mynet.com/istanbul/mekanlar/alisveris/alisveris-merkezi"
						},
	urlEncode:function(str) {
					key = new Array('ð','ü','þ','ö','ç','ý',' ');
					needle = new Array('%C4%9F','%C3%BC','%C5%9F','%C3%B6','%C3%A7','%C4%B1','+');

					for (i = 0; i<key.length; i++) {
						var re = new RegExp(key[i], "g");
						str = str.replace(re, needle[i]);
					}

					return str;
	},
	returnSearchOptions:function(keyword){
		keyword = keyword.toLowerCase().replace(",","").replace(" ","_");
		if(this.urls[keyword]){
			return this.urls[keyword];
		} else {
			return false;
		}
	},
	init:function(){
		var keyword = document.getElementById('fesmekan_value').value;
		if(keyword.length < 3){
			alert("Lütfen aramak için en az 3 harf giriniz");
			return false;
		}
		var url = this.returnSearchOptions(keyword);
		if(url){
			document.location.href = url + '?utm_source=mynet&utm_medium=www&utm_campaign=home_fesmekan_keyword';
		} else {
			document.location.href = this.default_url + this.urlEncode(keyword) + '&utm_source=mynet&utm_medium=www&utm_campaign=home_fesmekan_search';
		}
	}
};


var son_dakika = {
	href: Array(),
	title: Array(),
	counter: 0,
	timer: 0,
	init: function(){
		with(this){
			load();
			timer = window.setInterval(function(){
				load();
				if(counter == href.length + 1){
					counter = 0;
				} else {
					counter++;
				}
			},8000);
		}
	},
	load: function(){
		with(this){
			jQuery('#sondakika').attr('href',href[counter]);
			jQuery('#sondakika').html(title[counter]);
		}
	}
};

var video = {
	editor:{caption:'',username:'',view_count:'',url:'',image:'',lcid:''},
	most:{caption:'',username:'',view_count:'',url:'',image:'',lcid:''},
	last:{caption:'',username:'',view_count:'',url:'',image:'',lcid:''},
	sections: Array('editor','most','last'),
	titles: Array('','en çok izlenenler','en son eklenenler'),
	geri:{},
	ileri:{},
	gerispan:{},
	ilerispan:{},
	section: 0,
	init: function(){
		with(this){
			geri = jQuery('.mhVideoLinkBtn a')[0];
			ileri = jQuery('.mhVideoLinkBtn a')[1];
			gerispan = jQuery('.mhVideoLinkBtn span')[0];
			ilerispan = jQuery('.mhVideoLinkBtn span')[1];
			jQuery(geri).click(
				function(){
					load_section('geri');
				}
			);
			jQuery(ileri).click(
				function(){
					load_section('ileri');
				}
			);
		}
	},
	load_section: function(direction){
		with(this){
			if(direction == 'geri'){
				section--;
				if(section < 2){
					jQuery(ileri).show();
					jQuery(ilerispan).hide();
				}					
				if(section == 0){
					jQuery(geri).hide();
					jQuery(gerispan).show();
				}
			} else {
				section++;
				if(section > 0){
					jQuery(geri).show();
					jQuery(gerispan).hide();
				}
				if(section == 2){
					jQuery(ileri).hide();
					jQuery(ilerispan).show();
				}
			}
			jQuery('#video_title').html(titles[section]);
			jQuery('.mhVideoContent').fadeOut(400,function(){
				for(i = 0; i < 4; i++){
					//jQuery(jQuery('.mhVideoContain li')[i]).children('a').removeAttr('onclick');
					/*jQuery(jQuery('.mhVideoContain li')[i]).children('a').unbind('click').click(function(){
						_lcjson(video[sections[section]]['lcid'][jQuery('.mhVideoContain li').index(jQuery(this.parentNode))]);
					});*/
					jQuery(jQuery('.mhVideoContain li')[i]).children('a').children('em').children('img').attr('src',video[sections[section]]['image'][i]);
					jQuery(jQuery('.mhVideoContain li')[i]).children('a').children('em').children('img').attr('alt',video[sections[section]]['caption'][i]);
					jQuery(jQuery('.mhVideoContain li')[i]).children('a.mhVideoLink').attr('href',video[sections[section]]['url'][i]);
					jQuery(jQuery('.mhVideoContain li')[i]).children('a.mhVideoLink').attr('title',video[sections[section]]['caption'][i]);
					if(video[sections[section]]['username'][i] == 'mynet'){
						jQuery(jQuery('.mhVideoContain li')[i]).children('p').html(video[sections[section]]['view_count'][i]);
					} else {
						jQuery(jQuery('.mhVideoContain li')[i]).children('a').children('strong').html(video[sections[section]]['caption'][i]);
						jQuery(jQuery('.mhVideoContain li')[i]).children('a.mhVideoUser').attr('title',video[sections[section]]['username'][i]);
						jQuery(jQuery('.mhVideoContain li')[i]).children('a.mhVideoUser').html(video[sections[section]]['username'][i]);
						jQuery(jQuery('.mhVideoContain li')[i]).children('a.mhVideoUser').attr('href','http://video.mynet.com/'+video[sections[section]]['username'][i]+'?utm_source=mynet&utm_medium=www&utm_campaign=home_video_video_username_' + (i+1+(section*4)));
						jQuery(jQuery('.mhVideoContain li')[i]).children('p').html(video[sections[section]]['view_count'][i] + ' kez izlendi');
					}
				}
				jQuery('.mhVideoContent').fadeIn();
			});
		}
	}
};

var magazin = {
	init: function(){
		jQuery('.hoverl').hover(
			function()
			{
				var index = (jQuery(this.parentNode.parentNode).children().index(this.parentNode) - 1) / 2;
				var parent = this.parentNode.parentNode.parentNode;
				var serviceId = parent.id;
				var data = eval(serviceId + '_data');
				var image = jQuery('#'+serviceId+' img');
				image.attr('src',data['image'][index]);
				image.attr('alt',data['title'][index]);
				image.parent().attr('href',data['href'][index]);
				image.parent().attr('title',data['title'][index]);
			}
		);
	}
};

jQuery(document).ready(
	function()
	{
		init(); // interstatial
		havadurumu.init();
		son_dakika.init();
		video.init();
		magazin.init();
		jQuery('.hlink').hover(
			function()
			{
				jQuery('.mhNewsBigImg').css('display','none');
				jQuery('#'+this.id+'b').css('display','');
			}
		);
	}
);