/*
  _   _   _   _   _   _   _   _   _   _   _   _  
 / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ 
( X | H | T | M | L | K | I | T | C | H | E | N )
 \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ 
 
http://www.xhtmlkitchen.com

Client:     Orkid - http://www.orkid.com.tr
Author: 	Fatih Turan
Last-Edit: 	14:22 02.06.2008

*/

/*-------------------------------------------------------------------------
=GLOBAL FUNCTIONS
-------------------------------------------------------------------------*/
var flashvars = false;
var params = {
	wmode: "transparent"
};
var attributes = false;

swfobject.embedSWF("/images/swf/background_sub.swf", "header_flash", "100%", "220", "9.0.0", "", flashvars, params, attributes);
swfobject.embedSWF("/images/swf/bottom_sub.swf", "bottom", "100%", "243", "9.0.0", "", flashvars, params, attributes);
swfobject.embedSWF("/images/swf/eglence_sub.swf", "eglence_flash", "200", "250", "9.0.0", "", flashvars, params, attributes);



/*-------------------------------------------------------------------------
=POPUPS
-------------------------------------------------------------------------*/
var opened = '';
var products = '';
var ptimer = '';
var forms = '';

function togglePopup(popup,p) {
	
	var bg = $('blank_bg');
	var w_size = window.getSize();
	if($(popup) == undefined){
		togglePopup('loading_indicator','');
		var ajax =  new Ajax('/popups.php',{onComplete:function(){eval("togglePopup('loading_indicator','');"+'togglePopup("'+popup+'","'+p+'")');popupbut();},method:'get' , update:$('popups')});
		ajax.request();
	}else{
	var el = $(popup);
	
	if(el.getStyle('display') == 'none') {
			el.setStyles({display:'block'});
			var el_size = el.getSize();
		
			var left = (w_size.size.x-el_size.size.x)/2;
			var top  = (w_size.size.y-el_size.size.y)/2+(w_size.scroll.y);
		
			var sifr_title_h1 = 'div#'+popup+' h1';
		
			if($(p)){
				var size = $(p).getCoordinates();
				top = (size.top-el_size.size.y);
				left  = (size.left-(el_size.size.x-size.width)/2);
			}
		
			el.setStyles({left:left,top:top});
			bg.setStyles({display:'block','z-index':10,height:w_size.scrollSize.y});
			$('selectbox1').setStyles({visibility:'hidden'});
			opened = popup;
			//ptimer = setTimeout('togglePopup(opened)',10000)
		
		}else{
			//$clear(ptimer);
			el.setStyles({display:'none'});
			bg.setStyles({display:'none'});
			$('selectbox1').setStyles({visibility:'visible'});
			opened = '';
		}
	}
	
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
}

function jumpMenu( form ) { 

	var newIndex = form.selectedIndex; 
	cururl = form.options[ newIndex ].value;
	window.location.assign( cururl ); 

}

products = Class({
	create : function() {
		this.effect = new Fx.Styles($$('#selected_product img')[0],{duration:200, onComplete: function(){}, onStart: function(){}});
		$$('.products li a').addEvent('mouseover',function(el){
			product.effect.$events['onComplete'] = [function(){ product.effect.$events['onComplete'] = [];$$('#selected_product img')[0].src = '/images/content/discreet/'+this.id+'.gif';product.effect.start({'opacity':[0.1,1]});product.settitle(this.rel)}.bind(this)];
			product.effect.start({'opacity':[1,0.01]})
		})
	},
	settitle: function(str){
		var str = str.split(':');
		$('product-title').setHTML(str[0]);
		$('product-information').setHTML(str[1]);
		$('product-title').className = 'alternate';
		$('product-information').className = 'alternate';
		sIFR.replace(isgeb, {selector: 'div#content h1, div#content h1.alternate', css: ['.sIFR-root { color: #1e3b60; }'], wmode: 'transparent'});
		sIFR.replace(isg, {selector: 'div#content h2, div#content h2.alternate', css: ['.sIFR-root { color: #e7809b;}'], wmode: 'transparent'});
	}
	
});

form = Class({
	getData : function(){
		var data='';
		this.check = 1;
		
		if(opened == 'campaign'||opened == 'uye_ol')
			var a='2';
		else
			var a='';
		
		$$('#'+opened+'area'+a+' input').each(function(el){
			if(el.name == 'notnull' ){
				if(el.value == ''){
					this.check = 0;
				}
			}else if(el.name == 'email'){
				if(!echeck(el.value)){
					this.check = 2;
				}
			}
			data = data+(data==''?'':'&')+el.id+'='+el.value;
		}.bind(this));
		$$('#'+opened+'area'+a+' textarea').each(function(el){
			if(el.name == 'notnull' ){
				if(el.value == ''){
					this.check = 0;
				}
			}else if(el.name == 'email'){
				if(!echeck(el.value)){
					this.check = 2;
				}
			}
			data = data+(data==''?'':'&')+el.id+'='+el.value;
		});
		$$('#'+opened+'area'+a+' select').each(function(el){
			data = data+(data==''?'':'&')+el.id+'='+el.value;
		});
		data = data +'&url='+window.location.href;
		return data;
	},
	request : function(el){
		this.ajax =  new Ajax('/send.php?type='+opened,{method:'post',data:this.getData() , update:$(opened+'area')});
		if(this.check == 0){
			alert('İlgili alanları eksiksiz doldurunuz');
			return false;
		}else if(this.check == 2){
			alert('eposta adresleri geçersiz.');
			return false;
		}else{
			this.ajax.request();
		}
	},
	refresh : function(el){
		this.ajax =  new Ajax('/send.php?type='+opened,{onComplete:function(){$$('.submit').addEvent('click',function(el){forms.request();})},method:'post',data:'action=refresh' , update:$(opened+'area')});
		this.ajax.request();
	}
});

function popupbut(){
	if($$('.popup_close')){
		$$('.popup_close').addEvent('click',function(){
			forms.refresh();
			togglePopup(this.getParent().getParent().id,'');
		});
	
		$$('.popup_bottom_close').addEvent('click',function(){
			forms.refresh();
			togglePopup(this.getParent().getParent().id,'');
		});
	}
	$$('.submit').addEvent('click',function(el){forms.request();});
}

window.addEvent('domready',function(){
	
	$$('body')[0].innerHTML = '<div id="blank_bg" style="display:none;opacity: 0.5;-moz-opacity: 0.5; filter: alpha(opacity=50);"></div>'+$$('body')[0].innerHTML;
	
	$('blank_bg').addEvent('click',function(){
		forms.refresh();
		togglePopup(opened,'');
	});
	
	//navigation event
	$$("ul#sidebar_nav li a").addEvent('click',function(el) {
		if($(this).getNext()){
			this.getParent().getParent().getElements('ul').each(function(el){
				if(el.className == 'active')
					el.className = '';
			});
			if($(this).className == '')
				$(this).getNext().className = 'active';
			else
				$(this).getNext().className = '';
		}
	});
	
	product = new products();
	product.create();
	forms = new form();
	$$('.submit').addEvent('click',function(el){forms.request(this.rel);})
	
	if($(current['submenu']))
		$(current['submenu']).className = 'active';
	if($(current['mainmenu']))
		$(current['mainmenu']).className = 'active';
	if($(current['topic'])){
		
		if(current['topic'] != 'buyurken')
			$(current['topic']).className = 'active_topic';
		else
			$(current['topic']).className = 'active_topic2';
		
	}
	
	var accordion = new Accordion('h3.atStart', 'p.atStart', {
		opacity: false,
		duration: 200,
		onActive: function(toggler, element){
			toggler.getChildren()[0].className = 'active';
			element.style.padding = '5px 0 5px 0';
		},
		onBackground: function(toggler, element){
			toggler.getChildren()[0].className = '';
			element.style.padding = '0';
		}
	}, $$('.accordion')[0]);
	
	var d =  new Date();
	h = d.getHours();
	if(h> 19&&h < 24){
		$$('body')[0].id = 'night';
	}
	
	if(h > -1&&h < 7){
		$$('body')[0].id = 'night';
	}
	
  if($$('h3.atStart')[0]){ 
      window.onload = function(){
				$$('h3.atStart')[1].$events.click.values[0](); 
      	$$('h3.atStart')[0].$events.click.values[0]();
			}
  }
	
	if($('arkadasina_gonder_button')) {
      $('arkadasina_gonder_button').addEvent('click',function(){
              togglePopup('arkadasina_gonder','arkadasina_gonder_button');
      });
  }
	popupbut();
	
});

/*-------------------------------------------------------------------------
=SIFR CONFIGURATION
-------------------------------------------------------------------------*/
var isg = {src: '/images/fonts/ITC_Serif_Gothic.swf' };
var isgeb = {src: '/images/fonts/ITC_Serif_Gothic_Extrabold.swf' };
sIFR.activate(isg);
sIFR.activate(isgeb);
sIFR.replace(isgeb, {selector: 'div#content h1, div#content h2#product-title, div#content h1.alternate', css: ['.sIFR-root { color: #1e3b60; }'], wmode: 'transparent'});
sIFR.replace(isg, {selector: 'div#content h2, div#content h2.alternate, div#content h3.alternate', css: ['.sIFR-root { color: #e7809b;}'], wmode: 'transparent'});
sIFR.replace(isg, {selector: 'div#sidebar h1, div#sidebar h3', css: ['.sIFR-root { color: #e87e9e; font-weight:bold;}'], wmode: 'transparent'});