var boxy;

$(document).ready(function() {	
         	sIFR.replaceElement(named({sSelector:"span.Alt-Title", sFlashSrc:"/swf/impact.swf", sColor:"#FEF200", sBgColor:"#00ADEF", sWmode:"transparent", sWidth:"170", sHeight:"126", nPaddingTop:"3", nPaddingLeft:"3"}));
		    var options = { 
		        //target:        'Header',   // target element(s) to be updated with server response 
		        //beforeSubmit:  showRequest,  // pre-submit callback 
		        dataType: 'xml',

		        success:       function(data) {alert("hi")}  // post-submit callback 
			
    		    };
		$("a.Login").click(function() {
			$.ajax({
					  type: "GET",
					  url: "/index.php/login/ajax/",
					  data: "",
					  error: function(request,err,optexpt) {
					  
					     alert(request)
					  },
					  success: function(data){
					    if (boxy!==undefined) boxy.hideAndUnload();
					    boxy = new Boxy(data, {title: "Login"});
					    $("#Forgot-Pass-Link").click(function() {
					    
					    	$("#Login-Form").hide();
					    	$("#Forgot-Pass-Form").show();
					    	
					    	return false;
					    })
					    
					    
					   var loginOptions = { 
						success: function(data) {
						
						
						
					        testReponse("#Login-Form",data)		
    					    }} 					    
					    
					    
					    $("#Login-Form").find("form").ajaxForm(loginOptions);
    					    
  				            var options = { 
						success: function(data) {
					        testReponse("#Forgot-Pass-Form",data)		
    					    }}  					    
    					    
 					    $("#Forgot-Pass-Form").find("form").ajaxForm(options);   					    
					    
					    return false;
					  }
			});
			
		  
		  return false;
		
		})
		$("a.Register").click(function() {
			$.ajax({
				 type: "GET",
				 url: "/index.php/register/ajax/",
				 data: "",
				
				success: function(data){
					if (boxy!==undefined) boxy.hideAndUnload();
					boxy = new Boxy(data, {title: "Register"});
				        var options = { 
						success: function(data) {
					        testReponse("#Register-Form",data)		
    					}}
				        $("#Register-Form").find("form").ajaxForm(options);  
				}
				
			})			
		
		   return false;
		})
                function testReponse(id,data) {
			xmlDoc=getXML(data);
			
  			if ($(xmlDoc).find("title").text() == "Error") {
				$(id).find("div.Errors").html("<h3>"+$(xmlDoc).find("title").text()+"</h3><ul class='Error-List'></ul>");
				$(xmlDoc).find("li").each(function() {
					$(id).find("ul.Error-List").append("<li>"+$(this).text()+"</li>");
				})
				$(id).find("div.Errors").hide().slideDown();
					            	    
			} else {
				
				$("#Login-Links").empty();
				$(xmlDoc).find("li").each(function() {
					$("#Login-Links").append("<li>"+$(this).html()+"</li>");
				})
				
				
				boxy.hideAndUnload();
			}                   
                
                
                }
		
		function getXML(str) {
			try //Internet Explorer
			  {
			  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
			  xmlDoc.async="false";
			  xmlDoc.loadXML(str);
			  return xmlDoc;
			  }
			catch(e)
			  {
			  parser=new DOMParser();
			  xmlDoc=parser.parseFromString(str,"text/xml");
			  return xmlDoc;
  			}
		}
		
		
		
		// post-submit callback 
		function showResponse(responseText, statusText)  { 
		    alert("hi!")
		     
		        
		    return false;    
		} 
		
		
		
		
		
		
		$("a.Fade-Box").mouseenter(function() {
			$(this).find("span.Tag-Line").hide().animate({height: 'show', opacity: 'show'},'fast');												
		}).mouseleave(function() {
			$(this).find("span.Tag-Line").show().animate({height: 'hide', opacity: 'hide'},'fast');
		}).find("span.Tag-Line").hide()		   
		if ($("ul.Big-Carousel").find("li").size()>1) {				   
			$("div.Carousel").find("ul.Big-Carousel").jcarousel({scroll: 1, auto:3, wrap:"both"});
		}
		if ($("ul.Circle-Carousel").find("li").size()>1) {	
			$("div.Carousel").find("ul.Circle-Carousel").jcarousel({scroll: 1});		   
		}
		if ($("ul.Full-Carousel").find("li").size()>1) {	
			$("div.Carousel").find("ul.Full-Carousel").jcarousel({scroll: 4, wrap:"both"});
		}
		$("#Question-Box").css({ overflow: "hidden"}).rotator({ms:10000, autoHeight:false, n:1})


	
		/* channels box*/
		
		$("#Section-Selector").mouseenter(function() {
			$(this).find("ul").stop(true, true).hide().animate({height: 'show', opacity: 'show'},'fast');												
		}).mouseleave(function() {
			$(this).find("ul").stop(true, true).show().animate({height: 'hide', opacity: 'hide'},'fast');
		})
			
		$("#Main-Selector").mouseenter(function() {														
			$(this).find("ul").stop(true, true).hide().animate({height: 'show', opacity: 'show'},'fast');												
		}).mouseleave(function() {
			$(this).find("ul").stop(true, true).show().animate({height: 'hide', opacity: 'hide'},'fast');
		})	
		
		$("ul.News-List").find("li").mouseenter(function() {
			$(this).addClass("Hi-Light");										
		}).mouseleave(function() {
			$(this).removeClass("Hi-Light");	
		}).click(function() {
		    	window.location =  $(this).find("a:first").attr("href");
		   	return false;
		})
		
		$("ul.Similar-List").find("li").mouseenter(function() {
			$(this).addClass("Hi-Light");										
		}).mouseleave(function() {
			$(this).removeClass("Hi-Light");	
		}).click(function() {
		    window.location =  $(this).find("a:first").attr("href");
		    return false;
		})
			
		addPagerEvent();
		
		DD_roundies.addRule('.Article-Video', '50px', true);
		// videos 
		$('div.Comment-Body').find('a[href*=youtube.com/watch?v=]').each(function(){
		    $(this).wrap("<div class='Video-Embed'></div>");
		    $(this).parent().html("").flash({src: "/swf/player.swf", width: "100%", height: "100%", flashvars:{ file:this.href, image:"http://img.youtube.com/vi/"+jQuery.url.setUrl(this.href).param("v")+"/2.jpg",autostart:false,stretching:"fill", skin:"/swf/stylish.swf", backcolor:"#FFFFFF",frontcolor:"#000000",lightcolor:"#ED1B24"}}, {expressInstall: true, version: '9'});
		})	
		$('div.Comment-Body').find('a[href*=vimeo.com/]').each(function(){
		    href    = 'http://vimeo.com/moogaloop.swf?clip_id=' + jQuery.url.setUrl(this.href).segment(0) + '&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=ED1B24&amp;fullscreen=1'
		    $(this).wrap("<div class='Video-Embed'></div>");
		    $(this).parent().html("").flash({src: href, width: "100%", height: "100%"}, {expressInstall: true, version: '8'});	
			//$(this).parent().html("").flash({src: "/swf/player.swf", width: "100%", height: "100%", flashvars:{ file:"http://vimeo.com/3394667.swf",autostart:false,stretching:"fill", skin:"/swf/stylish.swf", backcolor:"#FFFFFF",frontcolor:"#000000",lightcolor:"#ED1B24",plugins:"/swf/vimeo.swf",type:"video"}}, {expressInstall: true, version: '9'});
		
		})
		
		
		$('div.Article-Video').find('a[href*=youtube.com/watch?v=]').each(function(){	    
			$(this).parent().html("").flash({src: "/swf/player.swf", width: "517", height: "318", flashvars:{ file:this.href, image:"http://img.youtube.com/vi/"+jQuery.url.setUrl(this.href).param("v")+"/0.jpg",autostart:false,stretching:"fill", skin:"/swf/stylish.swf", logo:"/images/logo.png", backcolor:"#000000",frontcolor:"#FEF200",lightcolor:"#ED1B24"}}, {expressInstall: true, version: '9'});	    
		})
		$('div.Article-Video').find('a[href*=vimeo.com/]').each(function(){
			href    = 'http://vimeo.com/moogaloop.swf?clip_id=' + jQuery.url.setUrl(this.href).segment(0) + '&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=ED1B24&amp;fullscreen=1'
			$(this).wrap("<div class='Video-Embed'></div>");
			$(this).parent().html("").flash({src: href, width: "517", height: "318"}, {expressInstall: true, version: '8'});	
		})
		
		var songs = $('#Songs').find('a[href*=.mp3]');
		
		if (songs.size()>0) {
		   AudioPlayer.setup("http://www.supersuper.tv/swf/mp3_player.swf", {width: 290,bg:"000000",leftbg:"ED1B24",lefticon:"FEF200",voltrack:"000000",volslider:"FEF200",rightbg:"000000",rightbghover:"000000",righticon:"FEF200",loader:"FFFFFF",track:"000000",tracker:"999999",border:"000000",text:"FFFFFF"}); 
		   
		}
		songs.each(function(i){	    
		     var song = $(this).attr("href");
		      var title = $(this).parent().find("span.Song-Title").text();
		       var artist = $(this).parent().find("span.Song-Artist").text();
			$(this).parent().parent().find("span.Song").attr("id","Song"+i);
			//$(this).parent().html("").flash({src: "/swf/player.swf", width: "517", height: "318", flashvars:{ file:this.href, image:"http://img.youtube.com/vi/"+jQuery.url.setUrl(this.href).param("v")+"/0.jpg",autostart:false,stretching:"fill", skin:"/swf/stylish.swf", logo:"/images/logo.png", backcolor:"#000000",frontcolor:"#FEF200",lightcolor:"#ED1B24"}}, {expressInstall: true, version: '9'});	    
	
	            AudioPlayer.embed("Song"+i, {soundFile: song, titles: title,  artists: artist});  
	        })
		
		
		
		$('div.Comment-Body').find("a[href$='.jpg'], a[href$='.png'], a[href$='.gif']").each(function() {

		    $(this).after("<img src='"+this.href+"' alt='' />");
		     $(this).remove();

		})	

		// comment replay to:
		$("a.Thread-Reply").click(function() {
			var id = $(this).parent().parent().parent().parent().parent().attr("id");
			//alert(id)
			id = id.replace("comment-", "");
			$("#Comment-ID").val(id);
		   //$("#Write-Comment").after($(this).parent().parent()[0]);
		   $(this).parent().parent().parent().parent().after($("#Write-Comment").parent().parent()[0])
		   // $("#Write-Comment").stop(true, true).hide().slideDown()

		  // .clone().prependTo("p");
		   return false;


		})


		// smooth scroll
		 $("h3.Title").find('a[href*=#]').click(function() {
			 if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
			 && location.hostname == this.hostname) {
			   var $target = $(this.hash);
			   $target = $target.length && $target
			   || $('[name=' + this.hash.slice(1) +']');
			   if ($target.length) {
			  var targetOffset = $target.offset().top;
			  $('html,body')
			  .animate({scrollTop: targetOffset}, 1000);
			    return false;
			   }
			 }
		  });
	var onMouseOutOpacity = 0.6;
	 $('#thumbs ul.thumbs li').css('opacity', onMouseOutOpacity).hover(function () {
		$(this).not('.selected').fadeTo('fast', 1.0);
	},function () {
		$(this).not('.selected').fadeTo('fast', onMouseOutOpacity);
	});
 
	var galleryAdv = $('#gallery').galleriffic('#thumbs', {
					delay:                  2000,
					numThumbs:              7,
					preloadAhead:           1,
					enableTopPager:         false,
					enableBottomPager:      true,
					imageContainerSel:      '#slideshow',
					controlsContainerSel:   '#controls',
					loadingContainerSel:    '#loading',
					renderSSControls:       true,
					renderNavControls:      true,
					playLinkText:           'Play Slideshow',
					pauseLinkText:          'Pause Slideshow',
					prevLinkText:           '&lsaquo; Previous Photo',
					nextLinkText:           'Next Photo &rsaquo;',
					nextPageLinkText:       'Next &rsaquo;',
					prevPageLinkText:       '&lsaquo; Prev',
					enableHistory:          false,
					autoStart:              false,
					onChange:               function(prevIndex, nextIndex) {
						$('#thumbs ul.thumbs').children()
							.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
							.eq(nextIndex).fadeTo('fast', 1.0);

					},
					onTransitionOut:        function(callback) {
						$("#loading").css("height",$('#slideshow').height()+"px");
						$('#slideshow').fadeOut('fast', callback);
					},
					onTransitionIn:         function() {
						$('#slideshow').fadeIn('fast');
						
					},
					onPageTransitionOut:    function(callback) {
						$('#thumbs ul.thumbs').fadeOut('fast', callback);
					},
					onPageTransitionIn:     function() {
						$('#thumbs ul.thumbs').fadeIn('fast');
					}
					
				});
	  
		  
		  
	$("#Ad-MPU").show();  

})

function addPagerEvent() {

		$("#Pager").find("a").click(function() {
			$("#Pager").find("p").html("<img src='http://"+location.host+"/images/load.gif' align='center' />");
			
			
			$.ajax({
			  type: "GET",
			  url: $(this).attr("href"),
			  
			  data: "",
			  success: function(data){
			    //alert( "Data Saved: " + data );
			    var holder = document.createElement("div");
			    
			    $(holder).html(data);

			    $("#Page-Box").append($(holder).find("li.DiscussionRow"));
			    
			    $("#Pager").html($(holder).find("#Pager").html());
			    addPagerEvent();
			    
			    holder=null;
			  }
			});
			return false;
		
		})


}
