function sld_toggle(type) {
	if (type == 'collection') {
		$('#collection_slideshow').show(); 
		$('#category_slideshow').hide(); 
		$('#tab_col').css({'background-color' :'#EEE'});
		$('#tab_cat').css({'background-color' :'#DDD'});
	} else {
		$('#collection_slideshow').hide(); 
		$('#category_slideshow').show(); 
		$('#tab_col').css({'background-color' :'#DDD'});
		$('#tab_cat').css({'background-color' :'#EEE'});
	}
}

 $(document).ready(function(){
    if(location.hash == '#sld_cat') {
        sld_toggle('category');
    }
	
	$('#fb_like_button').html('<a name="fb_share" type="button_count" share_url="'+_GPD.PAGE.url+'" href="http://www.facebook.com/sharer.php&u='+escape(_GPD.PAGE.url)+'&t='+escape(_GPD.PAGE.title)+'">Share</a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>');
		
	$('#tw_post_button').html('<a href="https://twitter.com/share" class="twitter-share-button" data-url="'+escape(_GPD.PAGE.url)+'" data-text="'+_GPD.PAGE.title+'" data-via="envyro" data-lang="en">Tweet</a><script type="text/javascript">!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>');
});

var Envy = {

	bagHovered : false,

	bagHoverId : 0,

	current_img_id : 1,
	
	SITE_URL : 'http://www.envy.ro',

	showSlides : function(url) {

		window.open(url, '123', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=775,height=620,left = 137,top = 80');

	},


	isValidEmail : function(str) {

		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
 
	},
	
	get_subcategories : function(parent_id) {
		$('#parent_id').attr('disabled', true);
		$('#category_id').attr('disabled', true);
		$.get(Envy.SITE_URL+"/gsc/"+parent_id, function(data) {
			var v = eval(data);
			var h = '';
			
			for(i = 0; i < v.gsc.length; i++) {
				h += '<option value="'+v.gsc[i].id+'">'+v.gsc[i].title+'</option>';
			}
			
			$('#category_id').html(h);
			
			$('#parent_id').attr('disabled', false);
			$('#category_id').attr('disabled', false);
		});
		
		return false;
	},

	doRegistration : function(email) {

		if (this.isValidEmail(email))	{

			document.location = Envy.SITE_URL+'/comunitate/bun-venit/'+email+'.html';

			return false;
		}

		else {

			alert('Adresa de email nu este valida!');

		}

		return false;

	},
	
	clearbox : function(elm, text) {
		if (elm.value == text) {
			elm.value = '';
		}
	},
	
	showImg : function(id) {

		var sImg = 'sImg' + id;

		var current_img = 'sImg' + this.current_img_id;

		current_img_id = id;

		var cimg = document.getElementById(current_img);

		cimg.style.display = "none";

		var cimg = document.getElementById(sImg);

		cimg.style.display = "block";
			
		$('#'+sImg).fadeIn('medium');
		
		this.current_img_id = id;

	},

	Scroller : {
	
		moving : true,

		currentScroll : 0,

		increment : 1,		
	
		speed : 50,
			
		direction : "left",

		scroll: function() {

			if( this.moving == 1 ) {

				var beforeScroll = this.scroller.scrollLeft;

				if (this.direction == "right"){

					this.scroller.scrollLeft -= this.increment;

					var afterScroll = this.scroller.scrollLeft;

					newvalue = this.scroller.scrollLeft/(this.scroller.scrollWidth-this.scroller.clientWidth);

					if (this.currentScroll != newvalue) {

						this.currentScroll = newvalue;

					}

					if(this.scroller.scrollLeft == 0 ) {

						this.direction="left";

					}
				}

				else {

					var beforeScroll = this.scroller.scrollLeft;

					this.scroller.scrollLeft += this.increment;

					var afterScroll = this.scroller.scrollLeft;

					newvalue = this.scroller.scrollLeft/(this.scroller.scrollWidth-this.scroller.clientWidth);

					if (this.currentScroll!= newvalue) {

						this.currentScroll = newvalue;

					}

					if( beforeScroll == afterScroll ) {

						this.direction="right";

					}
				}
			}
		},

		start : function() {

			this.moving = 1;

		},

		stop : function() {

			this.moving = 0;

		},

		init : function(scrollerId) {

			this.scroller = document.getElementById(scrollerId);	
			
			if ((this.scroller == undefined)) {

				return false;
			}

			else {return true}

		}

	},

	vote : function(id,rank) {	
		
		$('.vb').unbind('mouseover');

		$('.vb').unbind('mouseout');
			
		$('a.vb').attr('href','javascript:;');
 
		$.get(Envy.SITE_URL+"/vote/"+id+'/'+rank, function(data){

			var v = eval(data);

			document.getElementById('nrVotes').innerHTML = v.votes + ' voturi';
			
		if ( $.browser.msie) {
			document.getElementById('voteMsg').innerHTML = '<b>Va multumim pentru vot!</b>';
		}
		else {
			$('#voteMsg').fadeOut('medium', function() {

				document.getElementById('voteMsg').innerHTML = '<b>Va multumim pentru vot!</b>';

				$('#voteMsg').fadeIn('medium');

			});
		}	
			
		});
	},
	
	vote_me : function(id, rank) {	
		
		$('.vb').unbind('mouseover');
		$('.vb').unbind('mouseout');
		$('a.vb').attr('href','javascript:void(0);');
 
		$.get(Envy.SITE_URL+"/vote_me/"+id+'/'+rank, function(data){

		var v = eval(data);

		document.getElementById('nrVotes').innerHTML = v.votes + ' voturi';
		if ($.browser.msie) {
			document.getElementById('voteMsg').innerHTML = '<b>Va multumim pentru vot!</b>';
		}
		else {
			$('#voteMsg').fadeOut('slow', function() {
				document.getElementById('voteMsg').innerHTML = '<b>Va multumim pentru vot!</b>';
				$('#voteMsg').fadeIn('slow');
			});
		}	
			
		});
	},

	hoverBag : function(idx) {

		idx = Number(idx.substr(7,idx.length));
		
		for (i=1; i<=idx; i++ ) {

			id = '#votebag'+i;

			$(id).removeClass('votebag');
	
			$(id).addClass('votebag_hover');
			
		}

		this.bagHoverId = idx;

	},

	unhoverBag : function(idx) {
					
		idx = Number(idx.substr(7,idx.length));
		
		if (this.bagHoverId == idx) {

			for (i=1; i<=idx; i++ ) {

				id = '#votebag'+i;

				$(id).removeClass('votebag_hover');

				$(id).addClass('votebag');

			}

		}

		if (this.bagHoverId<idx)	{
					
			for (i=this.bagHoverId+1; i<=idx; i++ ) {

				id = '#votebag'+i;

				$(id).removeClass('votebag_hover');

				$(id).addClass('votebag');

			}
					
			this.bagHoverId = 0;

		}
	},

	reportComment : function(id) {
		
		$.get(Envy.SITE_URL+"/reportComment/"+id, function(){

			document.getElementById('comment'+id).innerHTML = '<b>Comentariul a fost raportat cu succes!</b>';

		});
		
	}

}
var tab_switch_interval = null;

window.onload = function() { 
	$('.votebag').mouseover( function() {
		Envy.hoverBag(this.id);		
	});

	$('.votebag').mouseout( function() {
		setTimeout("Envy.unhoverBag('"+this.id+"')",400);		
	});
		
	if (Envy.Scroller.init('scroller_container')) {
		setInterval("Envy.Scroller.scroll();", Envy.Scroller.speed);
	}
	
	if ($('#parent_id').val())
		Envy.get_subcategories($('#parent_id').val());
	
	tab_switch_interval = setTimeout('switch_hp_tab(0)', 2000);
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function open_slide_window(url) {
	window.open(url, '123', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=955,height=640,left = 137,top = 80');	
}
function slideShowNews(url) {
    window.open(url, '123', 'toolbar=0,location=0,scrollbars=1,resizable=1,statusbar=0,menubar=0,width=1050,height=840');    
}    

function switch_hp_tab(tabid, mode) {
	var tabcount = $('#hp_tabs a').size();
	if(mode=='auto') {
		tab_switch_interval = setTimeout('switch_hp_tab(0)',2000);
	} else {
		clearTimeout(tab_switch_interval);
	}
	if(tabid) {
		if(jQuery) {			
			for(i=1;i<=tabcount;i++)  {				
				$('#tab_content'+i).hide();		
				$('#tab'+i).attr('className', 'hp_tab');
			}
				
			$('#tab_content'+tabid).fadeIn();
			$('#tab'+tabid).attr('className', 'hp_current_tab');
		}
	} else {
		tabindex = 0;
		try { 
				$('#hp_tabs a').each(function(tid){
					if($(this).attr('className') == 'hp_current_tab') {
						if(tid+2>tabcount)
							tid = -1;
						switch_hp_tab(tid+2,'auto');
						throw true;
					}
				});
			}			
		catch(e) {}
		
		
	}
}

function google_ad_request_done(google_ads) {
	//console.debug(google_ads);
	var s = '';
	var i;
	if (google_ads.length == 0) {
		return;
	}
	if (google_ads[0].type == "flash") {
		s += '<a href=\"' +
		google_info.feedback_url + '\" style="color:#000000"><b>Ads by Google</b></a><br>' + 
		'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' +
		'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="' +
		google_ad.image_width + '" HEIGHT="' +
		google_ad.image_height + '"> <PARAM NAME="movie" VALUE="' +
		google_ad.image_url + '">' +
		'<PARAM NAME="quality" VALUE="high">' +
		'<PARAM NAME="AllowScriptAccess" VALUE="never">' +
		'<EMBED src="' +
		google_ad.image_url + '" WIDTH="' +
		google_ad.image_width + '" HEIGHT="' +
		google_ad.image_height +
		'" TYPE="application/x-shockwave-flash"' +
		' AllowScriptAccess="never" ' +
		' PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>';
	} else if (google_ads[0].type == "image") {
		s += '<a href=\"' +
		google_info.feedback_url + '\" style="color:#000000"><b>Ads by Google</b></a><br> <a href="' +
		google_ads[0].url + '" target="_top" title="go to ' +
		google_ads[0].visible_url + '" onmouseout="window.status=\'\'"onmouseover="window.status=\'go to ' +
		google_ads[0].visible_url + '\';return true"><img border="0" src="' +
		google_ads[0].image_url + '"width="' +
		google_ads[0].image_width + '"height="' +
		google_ads[0].image_height + '"></a>';
	} else if (google_ads[0].type == "html") {
		s += google_ads[0].snippet;
	} else {
		if (google_ads.length == 1) {
			var br_html = (ads_shape != 0) ? ' ' : '<br>';
			var rem_brk = (rem_br == 0) ? '<br>' : '&nbsp;&nbsp;';
			s += '<a href=\"' + google_info.feedback_url + '\" style="float: left; clear: both; color:#000000;font-size:12px;text-decoration: underline;"><b>Anunşuri Google</b></a><br><ul style="float: none; clear: both; margin: 5px 0px 0px 0px;">'
			for(i = 0; i < google_ads.length; ++i) {
				s += '<li style="'+li_style+'"><a style="'+url_title_style+'" href="' + google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' + google_ads[i].visible_url + '\';return true"> <span style="color: #850000; font-size: 13px; float: nonr; text-decoration:underline; text-align: left;"> ' + google_ads[i].line1 + '</span></a>'+rem_brk+'<span style="float: none; text-align: left;'+text_style+'">' +
				google_ads[i].line2 + br_html +
				google_ads[i].line3 + '<br></span> <span style="float: none; text-align: left;"><a style="'+url_link_style+'" href="' +
				google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' +
				google_ads[i].visible_url + '\';return true">' +
				google_ads[i].visible_url + '</span></a></li>';
			}
			s += '</ul>';
		} else if (google_ads.length > 1) {
			var br_html = (ads_shape != 0) ? ' ' : '<br>';
			var rem_brk = (rem_br == 0) ? '<br>' : '&nbsp;&nbsp;';
			s += '<a href=\"' + google_info.feedback_url + '\" style="float: none; clear: both; color:#000000;font-size:12px;text-decoration: underline;"><b>Anunşuri Google</b></a><br><ul style="float: none; clear: both; margin: 5px 0px 0px 0px;">'
			for(i = 0; i < google_ads.length; ++i) {
				s += '<li style="'+li_style+'"><a style="'+url_title_style+'" href="' + google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' + google_ads[i].visible_url + '\';return true"> <span style="color: #850000; font-size: 13px; float: left; text-decoration:underline; text-align: left;"> ' + google_ads[i].line1 + '</span></a>'+rem_brk+'<span style="float: none; text-align: left;'+text_style+'">' +
				google_ads[i].line2 + br_html +
				google_ads[i].line3 + '<br></span> <span style="float: left; text-align: left;"><a style="'+url_link_style+'" href="' +
				google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' +
				google_ads[i].visible_url + '\';return true">' +
				google_ads[i].visible_url + '</span></a></li>';
			}
			s += '</ul>';
		}
	}
	document.write(s);
	return;
}

