$(document).ready(function() {

	$(".sticky_item").css("cursor","pointer");
	$(".sticky_item").attr("title","Slide in article");
	$('.sticky_item').click(function() {
		$("#content-"+this.id).slideToggle();
	});
	
	$(".logoutbtn").css("cursor","pointer");
	$(".logoutbtn").attr("title","Log out");
	$('.logoutbtn').click(function() {
		$("#logoutform").submit();
	});
	
	$('#guestLogin 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 divOffset = $('#guestLogin').offset().top;
   				var pOffset = $('#guestLogin a[@name]').offset().top;
   				var pScroll = pOffset - divOffset;
   				$('#guestLogin').animate({scrollTop: '+=' + pScroll + 'px'}, 1000);
				return false;
			}
		}
	});	
	
	$('#userLogin 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 divOffset = $('#userLogin').offset().top;
   				var pOffset = $('#userLogin a[@name]').offset().top;
   				var pScroll = pOffset - divOffset;
   				$('#userLogin').animate({scrollTop: '+=' + pScroll + 'px'}, 1000);
				return false;
			}
		}
	});	


	$('a.user-prefs').click(function(){
		window.open(this.href,"prefs","location=0,status=0,scrollbars=0,width=250,height=300");
		return false;
	});
	
	$('a.terms-pop').click(function(){
		window.open(this.href,"prefs","location=0,status=0,scrollbars=1,resizable=1,width=350,height=400");
		return false;
	});
	
	
	$("#submit_guestlogin").css("cursor","pointer");
	$("#submit_guestlogin").attr("title","Log in as guest");
	$('#submit_guestlogin').click(function(){
		if(document.submit_guestlogin_form.password.value.length<4){
			$('#alertmessage').html("<span>Guest password needed!</span>")
		}else{
			$('#alertmessage').html("Wait...")			
			document.submit_guestlogin_form.submit();	
		}
	});  
	
	$("#submit_login").css("cursor","pointer");
	$("#submit_login").attr("title","Log in");
	$('#submit_login').click(function(){
		if(document.submit_login_form.email.value.length<5){
			$('#alertmessage').html("<span>Your email address, please.</span>")
		}else{
			$('#alertmessage').html("Wait...")			
			document.submit_login_form.submit();	
		}
	});  
	
	$("#submit_guestapply").css("cursor","pointer");
	$("#submit_guestapply").attr("title","Apply for guest password");
	$('#submit_guestapply').click(function(){
		if(document.submit_guestapply_form.name.value.length<2){
			$('#alertmessage').html("<span>Your name, please.</span>")
		}else if(document.submit_guestapply_form.email.value.length<5){
			$('#alertmessage').html("<span>Your email address, please.</span>")
		}else if(document.submit_guestapply_form.company.value.length<1){
			$('#alertmessage').html("<span>Company name, please.</span>")
		}else if(document.submit_guestapply_form.title.value.length<2){
			$('#alertmessage').html("<span>Your job title, please.</span>")
		}else if(!document.submit_guestapply_form.tcagree.checked){
			$('#alertmessage').html("<span>You have to agree to our terms and conditions.</span>")
		}else if(!document.submit_guestapply_form.privacyagree.checked){
			$('#alertmessage').html("<span>You have to agree to our privacy policy.</span>")
		}else{
			$('#alertmessage').html("Wait...")	
			document.submit_guestapply_form.submit();	
		}
	}); 
	
	$("#submit_userapply").css("cursor","pointer");
	$("#submit_userapply").attr("title","Apply for a user");
	$('#submit_userapply').click(function(){
		if(document.submit_userapply_form.name.value.length<2){
			$('#alertmessage').html("<span>Your name, please.</span>")
		}else if(document.submit_userapply_form.email.value.length<5){
			$('#alertmessage').html("<span>Your email address, please.</span>")
		}else if(document.submit_userapply_form.phone.value.length<5){
			$('#alertmessage').html("<span>Your phone number, please.</span>")
		}else if(document.submit_userapply_form.company.value.length<1){
			$('#alertmessage').html("<span>Company name, please.")
		}else if(document.submit_userapply_form.title.value.length<2){
			$('#alertmessage').html("<span>Your job title, please.</span>")
		}else if(!document.submit_userapply_form.tcagree.checked){
			$('#alertmessage').html("<span>You have to agree to our terms and conditions.</span>")
		}else if(!document.submit_userapply_form.privacyagree.checked){
			$('#alertmessage').html("<span>You have to agree to our privacy policy.</span>")	
		}else{
			$('#alertmessage').html("Wait...")			
			document.submit_userapply_form.submit();	
		}
	}); 
	
	$("#submit_userchange").css("cursor","pointer");
	$("#submit_userchange").attr("title","Update your profile");
	$('#submit_userchange').click(function(){
		if(document.submit_userchange_form.name.value.length<2){
			$('#alertmessage').html("<span>Your name, please.</span>")
		}else if(document.submit_userchange_form.phone.value.length<5){
			$('#alertmessage').html("<span>Your phone number, please.</span>")
		}else if(document.submit_userchange_form.company.value.length<1){
			$('#alertmessage').html("<span>Company name, please.")
		}else if(document.submit_userchange_form.title.value.length<2){
			$('#alertmessage').html("<span>Your job title, please.</span>")
		}else{
			$('#alertmessage').html("Wait...")			
			document.submit_userchange_form.submit();	
		}
	}); 
	 
	$(function() {  
		$("#submit_guestlogin_form input").keypress(function (e) {  
			if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {  
				 $("#submit_guestlogin_form").submit();
				return false;  
			} else {  
				return true;  
			}  
		});  
	});
	$(function() {  
		$("#submit_login_form input").keypress(function (e) {  
			if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {  
				 $("#submit_login_form").submit();
				return false;  
			} else {  
				return true;  
			}  
		});  
	});
	$(function() {  
		$(".naviselect").change(function(){
			var naviselecturl=$(this).val();
			if(naviselecturl){
				document.location.href=naviselecturl;
			}
		});
	});	
	
	$("#mainContent .logoList .postCol2 a").click(function(){
		alert("This file can only be used by press or partners marketing MTV Networks.");
	});
	$("#mainContent .photoList li a").click(function(){
		alert("This file can only be used by press or partners marketing MTV Networks.");
	});
	
	if($("#mediaplayer").length>0){
		videopath=$("#mediaplayer").text();
	    var s1 = new SWFObject("/img/player.swf","mediaplayer","315","270","7");
	    s1.addParam("allowfullscreen","true");
	    s1.addVariable("file","/uploads/public/"+videopath);
		s1.addVariable('skin', '/img/modieus.swf');	
		s1.addVariable('autostart', 'true');			
	    s1.write("mediaplayer");		
	}


});
