onDomReady(function () {

	// fx --scroll
	new SmoothScroll({ duration: 900 });

	// init
	flix.initialize();

});




var flix = new Abstract({

	// movie id
	id:1,

	// authentication if user is login set "true"
	isLogin: function() {
		return (document.getElementById("SignIn") == null);
	},

	// --global user id
	userId:1, // insert here the user id

	//timer for all the calls
	timer:0,

	// Fans & Idols small tab default mode
	FanTabId:'MyFans', //or FanOf

	mySlide:null,

	_mailRx:/^[\w-\.]+@([a-z0-9\-]+\.)+[a-z]{2,5}$/i,
	ValidEmail: function(e){return flix._mailRx.test(e);},

	// init
	initialize: function() {
		// get data
//		var updater = new Ajax('generic/data.php?'+flix.id, {method: 'get'}).request();


		//Fans & Idols small tabs control - set default tab
		if($("FansList"))
			flix.updateRC_FanIdols();

		if($("selectMenuContainer"))
			flix.initToggleSelect();

	},

	//gets the value of any requested 'item' from query string
	getItemFromQueryString: function(item){

		var objURL = new Object();
		window.location.search.replace(
			new RegExp( "([^?=&]+)(=([^&]*))?", "g" ),
			function( $0, $1, $2, $3 ){
				objURL[ $1 ] = $3;
			}
		);


		return objURL[item];
	},

	initToggleSelect: function(){


		flix.mySlide = new Fx.Slide('selectMenuLB');
		flix.mySlide.hide();

		$('toggle').addEvent('click', function(e){
			e = new Event(e);
			flix.mySlide.toggle();
			e.stop();
		});
		if($("selectMenuContainer"))
			$("selectMenuContainer").style.display="block";

	},
    IsInteger: function(txt)
    {
        if(txt.indexOf('.') == -1)
        {        
          return true;
        }
        return false;
    
    },


	//show / hide select menu
	setSelect_Yellow:function(lb,el){
		//alert($(lb).style.display);

		if($('arrow').src.indexOf("_up.gif") == -1)
		{
			//flix.showIt(lb, el);
			$('arrow').src="/images/buttons/yellowselect_button_up.gif";
		}
		else
		{
			//flix.hideIt(lb, el);
			$('arrow').src="/images/buttons/yellowselect_button.gif";
		}
	},

	//on selected item click - fire the function with parametrs
	selectItem_Yellow: function(param,f,el){

		//flix.hideIt('selectMenuLB', this);
		flix.mySlide.toggle();
		$('arrow').src="/images/buttons/yellowselect_button.gif";
		f(param,$(el));
		},

	//show / hide select menu
	setSelect_Red:function(lb,el,ev){

		if($('arrow').src.indexOf("_up.gif") == -1)
		{
			//flix.showIt(lb, el);
			$('arrow').src="/images/buttons/redSelect_button_up.gif";
		}
		else
		{
			//flix.hideIt(lb, el);
			$('arrow').src="/images/buttons/redSelect_button.gif";
		}

	},


	//----------------------------------------------------------------------------------//
	// user & personal page(content) - swap Fans & Idols small tab
	changeFansTab: function(o){
		if(flix.FanTabId != $(o).id) {
			$(flix.FanTabId).removeClass('current');
			$(o).addClass('current');
		}
		flix.FanTabId = $(o).id;
		flix.updateRC_FanIdols();

	},

	//----------------------------------------------------------------------------------//
	// update user & personal page(Ajax content)
	// <params>
	// userId,FanTabId
	// </params>
	updateRC_FanIdols: function() {
		return;
/*		flix.showReloader('Update...','update'); // Violet
		var updater = new Ajax('includes/user/rcUser.php?tabId='+ flix.FanTabId + '&r=' + Math.floor(Math.random()*100)  , {method: 'get', update: $('FansList'), onComplete:function(){
			flix.hideReloader(); // hide reloader
			if($(flix.FanTabId)) $(flix.FanTabId).addClass('current');
		}}).request();
*/
	},


	// show it
	showIndex:null,
	becomeafan: function(o, el, inProfilePage) {
		if(flix.isLogin()) {
			flix.showReloader('Update...','update'); // Violet
			var poster = new Ajax("/movie/fan?broadcasterId="+Common.GetBroadcasterId()+"&add=true", {method:'get', onComplete:function() {
				var status = eval(this.transport.responseXML.firstChild.getAttribute("success"));
				flix.hideReloader(); // hide reloader
				if (status) flix.showIt(o, el);

				if (el.innerHTML.toUpperCase() == "REMOVE ME") {
					$(o).getElementsByTagName("div")[0].innerHTML = "You are not a fan anymore...";
					el.innerHTML = (inProfilePage) ? "Become a fan" : "BECOME A FAN";
				} else {
					if (inProfilePage) el.style.visibility = "hidden";
					$(o).getElementsByTagName("div")[0].innerHTML = "You are a fan now :)!";
					el.innerHTML = (inProfilePage) ? "Remove me" : "REMOVE ME";
				}
			}}).request();
		} else flix.login(el);
	},
    showItAnyways: function(o, el) 
    {
        //debugger;
        if($(o)) 
        {

            if(o != flix.showIndex && flix.showIndex != null && o != null) 
            {
                var last = flix.showIndex;

                    var fx = $(last).effect('opacity', {duration: 500, onComplete: function() {
                        $(last).hide();
                    }}).start(0);
            }
            
            flix.showIndex = o;


			if (el.id == 'flixee') 
            {
				$(o).style.top = ((getElementPos(el).y)-167+20)+"px";
			}

            var el = $(o);
            el.setStyle('opacity','0');
            el.show();
            var fx = el.effect('opacity', {duration: 500, onComplete: function() {

            }}).start(1);
        }
    }, 
	showIt: function(o, el) {
		if(flix.isLogin()) {
			if($(o)) {

				if(o != flix.showIndex && flix.showIndex != null && o != null) {
				var last = flix.showIndex;

					var fx = $(last).effect('opacity', {duration: 500, onComplete: function() {
						$(last).hide();
					}}).start(0);
				}
				flix.showIndex = o;

				var el = $(o);
				el.setStyle('opacity','0');
				el.show();
				var fx = el.effect('opacity', {duration: 500, onComplete: function() {

				}}).start(1);
			}
		} else { flix.login(el); }
	},

	hideIt: function(o) {

		if(($(o)) && ($(o) != null)) {
			var fx = $(o).effect('opacity', {duration: 500, onComplete: function() {
				$(o).hide();
			}}).start(0);
		}
	},

	// login user
	login: function(el) {
		var obj = $('logInBox');
		var eObj = $(el);
		var clickedObjLeft = eObj.offsetLeft;
		if (clickedObjLeft == 0) {
			var cObj = eObj;
			while (clickedObjLeft == 0 && cObj != null && cObj.tagName != "BODY") {
				clickedObjLeft += parseInt(cObj.offsetLeft);
				cObj = cObj.offsetParent;
			}
		}
		var fixed = obj.offsetLeft; // culculate clicked element left

		var o = obj.setStyles({
			left:clickedObjLeft,
			top:(eObj.getTop()+20)
			});

		if($(o)) {
			$(o).setStyle('opacity','0');
			$(o).show();
			var fx = $(o).effect('opacity', {duration: 400, onComplete: function() {
				flix.showIndex = $(o);
			}}).start(1);
		}
	},


	// login user
	alertMe: function(el,d) {
		var obj = $(d);
		var eObj = $(el);
		var clickedObjLeft = eObj.offsetLeft;
		var fixed = obj.offsetLeft; // culculate clicked element left

		var o = obj.setStyles({
			left:clickedObjLeft,
			top:(eObj.getTop()+20)
			});

		if($(o)) {
			$(o).setStyle('opacity','0');
			$(o).show();
			var fx = $(o).effect('opacity', {duration: 400, onComplete: function() {
				flix.showIndex = $(o);
			}}).start(1);
		}
	},



	// find element position --temprory
	findPos: function(obj) {
		var curleft = curtop = 0;
		if (obj.offsetParent) {
			curleft = obj.offsetLeft
			curtop = obj.offsetTop
			while (obj = obj.offsetParent) {
			      curleft += obj.offsetLeft
			      curtop += obj.offsetTop
			}
	      }
		return [curleft,curtop];
	},



	// show reloader
	// content - may be any text or html tags
	// task - is options for colors (load, send, update)
	showReloader: function(content, task) {
		var o = $('reloader');
		if (typeof(o) == "undefined" || o == null) {
			window.status = "there is no reloader on this page...";
			return;
		}
		o.setHTML(content);
		

		if (document.all) {
			
		} else {
			o.style.top = window.scrollY+"px";
		}

		switch(task) {
			case 'load':
				o.setStyle('background','#E30A17'); // red
				break
			case 'send':
				o.setStyle('background','#78BA91'); // green
				break
			case 'update':
				o.setStyle('background','#7389AE'); // violet
				break
			default:
				//code to be executed if n is
				//different from case 1 and 2
		}
		o.setStyle('background','#E30A17'); // red
		o.show();
	},

	// hide reloader after all Ajax request
	hideReloader: function() { var o = $('reloader'); o.hide();  },
	
	liveIndicatorInterval:0, 
	
	showLiveIndication: function(id) {
		if ($("liveIndication")) $("liveIndication").style.display = "";
	}, 
    
    gotoLocation: function(loc){
        window.location.href = loc;
    },
	
	hideLiveIndication: function() {
		if ($("liveIndication")) $("liveIndication").style.display = "none";
	},
    isIE: function()
    {
        return (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
    }
    
    
    
    
    
    
    
    
});





