google.load("jquery","1.4.2");
google.load("jqueryui", "1.8.0");
	
google.setOnLoadCallback(function(){

	$jQ=jQuery.noConflict();
	$=$jQ;
	
	$jQ.ajaxSetup({async: false});
	$jQ.getScript("http://androidapplications.com/js/jquery.ui.tabs.js");
	$jQ.ajaxSetup({async: true});
			
	$jQ.ajaxSetup({async: false});
	$jQ.getScript("http://androidapplications.com/js/handies.js");
	$jQ.ajaxSetup({async: true});
	
	$jQ.ajaxSetup({async: false});
	$jQ.getScript("http://androidapplications.com/js/facebox.js");
	$jQ.ajaxSetup({async: true});
	
	$jQ.ajaxSetup({async: false});
	$jQ.getScript("http://androidapplications.com/js/jquery.colorbox.js");
	$jQ.ajaxSetup({async: true});
	
	//$jQ('a[rel*=facebox]').facebox();

                var selectedWidgetTab = 'tab-outer-0';

                $jQ('ul.sidebarWidgetsTabbed .nav ul li a').click(function() {

                    var aTarget = $jQ(this);

                    if($jQ(this).attr('rel') != selectedWidgetTab) {
                        $jQ('.widget_content').fadeOut('slow', function() {
                            setTimeout(function() { $jQ('#' + $jQ(aTarget).attr('rel')).fadeIn('slow'); }, 500);
                        });

                        $jQ('ul.sidebarWidgetsTabbed .nav ul li').removeClass('active');

                        $jQ(aTarget).parent().addClass('active');

                        selectedWidgetTab = $jQ(aTarget).attr('rel');
                    }

                    return false;

                });

                $jQ('#temp_Subnav ul li a').hover(
                function() {
                    var imgSrc = $jQ(this).find('img').attr('src');

                    imgSrcSplit = imgSrc.split('_');

                    imgSrcSplit[imgSrcSplit.length - 1] = 'over.jpg';

                    $jQ(this).find('img').attr('src', imgSrcSplit.join('_'));
                },
                function() {
                    var imgSrc = $jQ(this).find('img').attr('src');

                    imgSrcSplit = imgSrc.split('_');

                    imgSrcSplit[imgSrcSplit.length - 1] = 'normal.jpg';

                    $jQ(this).find('img').attr('src', imgSrcSplit.join('_'));
                }
                );
				
	if ($jQ.browser.mozilla) {
    
		//alert("you are using Firefox!");
		$jQ(".appsList").css("marginRight","10px");
		$jQ(".leftnav").css("marginTop","-30px");
		
	}
	
	if($jQ(".popups").length) {
		$jQ(".popups").colorbox({
									
			height: "90%"
									
									});
		$jQ(".viewreview").colorbox({
									
			width: "700px",
			height: "90%"
									
									});
	}
	
	$jQ(".android_app_thumb").click(function(){
		
		window.location.href=($jQ(this).children("h2").children("a").attr("href"));
		
	});
	
	if($jQ("#starsHover").length) { $jQ("#starsHover").hover(function(){ $jQ("#ratingDisplay").css("display","block"); },function(){ $jQ("#ratingDisplay").css("display","none"); }); }
	
	if($jQ('.loginLink').length) {
	    $jQ('.loginLink').colorbox({
	        width: "300px",
	        inline: true,
	        href: "#inlinelogin"
	    });
	}
	

	
	if(len("#rightSidebar")) { 
	
		$jQ("#temp_Footer").css("background-image","url(http://phandroid.com/wp-content/themes/mroar/images/footer.jpg)");
		$jQ("body").attr("class","viewPage");	
		
	
	}
		
	$jQ("#searchTextbox").focus(function(){
	
		$jQ(this).css({

			color: "#000",
			fontStyle: "normal"
					
		}).attr("value","");
									  
	});
	
	$jQ("#username").css({
	
		color: "#ddd",
		fontStyle: "italic"
												  
	}).attr("value","username").focus(function(){
	
		$jQ(this).css({

			color: "#000",
			fontStyle: "normal"
					
		}).attr("value","");
									  
	});
	
	$jQ("#password").css({
	
		color: "#ddd",
		fontStyle: "italic"
												  
	}).attr("value","password").focus(function(){
	
		$jQ(this).css({

			color: "#000",
			fontStyle: "normal"
					
		}).attr("value","");
									  
	});
	
	$jQ("#topUpVote").click(function(){
								  
		if(upVTed==false) {
	
				if(dnVTed==true) {
				
					dnVN=jQuery('#topDownVote .thumbNumber');
					dnVNum=(parseInt(dnVN.html()))-1;
					dnVN.html(dnVNum);
				


				}
	
				upVN=jQuery('#topUpVote .thumbNumber');
				upVNum=(parseInt(upVN.html()))+1;
				upVN.html(upVNum);
				voted=true;
				upVTed=true;
				dnVTed=false;
				
		}
								  
								  });
	
	$jQ("#topDownVote").click(function() {
		
		if(dnVTed==false) {
		
			if(upVTed==true) {
			
				upVN=jQuery('#topUpVote .thumbNumber');
				upVNum=(parseInt(upVN.html()))-1;				
				upVN.html(upVNum);
			
			}
	
				dnVN=jQuery('#topDownVote .thumbNumber');
				dnVNum=(parseInt(dnVN.html()))+1;
				dnVN.html(dnVNum);
				voted=true;
				dnVTed=true;
				upVTed=false;
		
		}
									
									});
	
	$jQ("#stupidClickHere").attr("href",$jQ("#postReview").children("a").attr("href"));
	
	if($jQ(".previous").length>0) { $jQ(".paginationControl").css("width","450px"); }
	
	if($jQ("#summary").length>0) { $jQ("#summary-element").append('<div id="counter"><em>Characters left: <span class="under">50</span><em></div><div id="bottomLineWarning">Please do not use the application title in the bottom line.</div>'); }
	
	thisPageURL=window.location.href;
	
	$jQ("#addToAnyLink").click(function(){alert("http://www.addtoany.com/share_save?linkurl="+escape(thisPageURL))});
	
	$jQ(".unWrapHotspot").click(function(){ appUnwrap($("#hiddenDiv"+$(this).attr("rel")).parent()); }).each(function(){
	
		$(this).width($("#appListTable").width());
																		
	});
		
	$(".closeButton").click(function(){
		
		if($(this).css("background-image").indexOf("rightarrow")>0) {

			$(this).css("background-image","url('http://androidapplications.com/images/button_downarrow.png')").parent().children(".closeOpenMessage").html("Close");
			
		} else {
			
			$(this).css("background-image","url('http://androidapplications.com/images/button_rightarrow.png')").parent().children(".closeOpenMessage").html("Learn More");
			
		}
	
		$(this).parent().parent().parent().find(".hiddenDiv").slideToggle("slow");
		
			return false;
									   
	});

	$("#blackListTable .blackListTR").click(function(){
	
		window.location.href=$(this).children("td").eq(0).children("a").attr("href");
	
	});
	
	if(len("#upDownVotes")) {
	
		$("#topUpVote").click(function(){
		
			if(isLoggedIn()) {
			
				$.post(

					$(this).attr('href'),

					{},

        			function(data) {
						alert(data.up+'/'+data.down+' - Your vote has been cast!');
	      			},

    	    		'json'

      			);
				
			} else {
				
				alert("You must login.");

			}

			return false;
									   
		});
		
	}
	
	$(".altRows:odd").addClass("oddRow");
	
	$("tr.primary td .app_category .text").each(function(){

		toMoveDown=(($(this).parent().parent().height()/2) - ($(this).height()/2))+"px";


		$(this).css({
	
			position: "relative",
			top: toMoveDown
		
		}).html($(this).html().replace("\/"," / "));
																						 
	});
	
	$(".clickToReveal").click(function(){
	
		// alert($(this).attr("href"));
	
		elementID=$(this).attr("href");		
		$(elementID).slideToggle("slow");
		return false;
																		 
	});

});

function len(elementName) {

	return $jQ(elementName).length;
	
}

function isLoggedIn() {
	
	$.get('/is_logged_in', function(data) {
		return data.is_logged_in;
	},"json");
	
}

function appUnwrap(elementID) {
	
	thisTD=elementID;
		
	thisTD.children(".hiddenDiv").slideToggle();
		
	if(thisTD.parent().find(".closeButton").css("background-image").indexOf("rightarrow")>0) {

		thisTD.parent().find(".closeButton").css("background-image","url('http://androidapplications.com/images/button_downarrow.png')").parent().children(".closeOpenMessage").html("Close");
			
		thisTD.find(".app_short_desc").fadeOut();
		thisTD.parent().find(".screenshots").fadeIn();
			
	} else {
			
		thisTD.parent().find(".closeButton").css("background-image","url('http://androidapplications.com/images/button_rightarrow.png')").parent().children(".closeOpenMessage").html("Learn More");
			
		thisTD.find(".app_short_desc").fadeIn();
		thisTD.parent().find(".screenshots").fadeOut();
			
	}
	
}
