
var slideold;

jQuery(document).ready(function($){ 	
	
	$("#footer ul li:first-child").css("border","none");
		
	slideshow("slider-violet");
	$("#main #mslider ul li a").mouseover(function() {
		var o = $(this);
		var meme = jQuery(this).attr("rel");		
		if ((meme != null) && (slideold != meme)) slideshow(meme); 
			
	});		
	
	
	jQuery("#main #mtop #mslider .mslide").each(function() {
		var sublink = jQuery(this).find("a").attr("href");
		var img = $(this).css("background-image"); img = img.substring(5,img.length-2);
		
		var content = $(this).html();
		$(this).html("<div class='divbg'><img src='"+img+"'/></div><div class='divcont'>"+content+"</div>");		
		
		$(this).attr("alt",sublink); //alert(img);
	});
	
	$("#mbottom .msubbox").each(function() {
		var sublink = $(this).find("a").attr("href");		
		$(this).attr("alt",sublink);		
	});
	
	$("#main .msubbox").each(function() {
		var img = $(this).css("background-image"); img = img.substring(5,img.length-2);		
		var content = $(this).html();
		$(this).html("<div class='divbg'><img src='"+img+"'/></div><div class='divcont'>"+content+"</div>");	
	});

	$("#main #mtop #mslider  .mslide").click(function(){
		var link = $(this).attr("alt");		
		document.location = link;
	});
	
	$("#mbottom .msubbox").click(function(){
		var link = $(this).attr("alt");
		document.location = link;		
	});	
	
	
	if (($.browser.msie && $.browser.version) == '6.0'){  
		
		jQuery("#header #menu_top ul li").hover( 
			function () { jQuery(this).find("ul").css("display","block"); },   
			function () { jQuery(this).find("ul").css("display","none"); }   
		);
	}

	$("#mypopup a").click(function(){
		if ($("#mypopup div").css("display") == "none"){
			$("#mypopup div").css("display","block");  
		} else {
			$("#mypopup div").css("display","none");  
		}
		return false;
	});
});

function slideshow(a){	
	//alert(a);
	
	if (slideold == null){	
		$("#main #mslider #slider-violet").fadeTo(0, 0);
		$("#main #mslider #slider-blue").fadeTo(0, 0);
		$("#main #mslider #slider-orange").fadeTo(0, 0);
		$("#main #mslider #slider-lime").fadeTo(0, 0);

		$("#main #mslider #"+a).fadeTo(500,1);
		
		$("#main #mslider #slider-violet").hide(0);
		$("#main #mslider #slider-blue").hide(0);
		$("#main #mslider #slider-orange").hide(0);
		$("#main #mslider #slider-lime").hide(0);
		$("#main #mslider #"+a).show(0);
	} else {
		$("#main #mslider #"+a).fadeTo(250,1);
		$("#main #mslider #"+slideold).fadeTo(500, 0);
		
		$("#main #mslider #slider-violet").hide(0);
		$("#main #mslider #slider-blue").hide(0);
		$("#main #mslider #slider-orange").hide(0);
		$("#main #mslider #slider-lime").hide(0);
		$("#main #mslider #"+a).show(0);
	}
	
	slideold = a;
	//$("#main #mslider #"+a).fadeTo(1000,1);
}


function mypopup(a,b){
	//alert(themedir);
	
	if (a == "download"){
		if (b=="close"){
			$("#mypopup div").css("display","none");
			
		} else if (b=="submit"){
			var txtname = $("#mypopup #txtname").val();
			var txtsurname = $("#mypopup #txtsurname").val();
			var txtcountry = $("#mypopup #txtcountry").val();
			var txtpostcode = $("#mypopup #txtpostcode").val();
			var txtemail = $("#mypopup #txtemail").val();
			var txtform = $("#mypopup #txtform").val();
			
			var yeah = "&name="+txtname+"&surname="+txtsurname+"&country="+txtcountry+"&postcode="+txtpostcode+"&email="+txtemail+"&form="+txtform;
			yeah = yeah.replace(/ /gi,"_");
			//alert(yeah);					
			
			if (is_null(txtname) || is_null(txtsurname) || is_null(txtcountry) || is_null(txtpostcode) || is_null(txtemail)){
				alert("Please fill-up all fields!");
			} else {
				$("#form_dl").load(themedir+"/mydata/script.php?do=download"+yeah);
			}
		}
		
	} else if (a == "volunteer"){
		
		if (b=="submit"){
			
			var venue = $('input:radio[name=venue]:checked').val();
			var email = $("#form_volunteer #txtemail").val();			
			
			var yeah = "&venue="+venue+"&email="+email;
			yeah = yeah.replace(/ /gi,"_");
			//alert(yeah);	
			
			if (is_null(email)) {
				alert("Please enter your email!");
			} else {
				
				$("#form_volunteer").load(themedir+"/mydata/script.php?do=volunteer"+yeah);
			}
		}
	}
}

function is_null(a){
	a = a.replace(/^\s*|\s*$/g,'');	
	if (a == ""){ return 1 } else { return 0 }
}

// http://localhost/wp/wp-content/themes/112410_mayur_color/mydata/script.php?do=get_download_list
// http://localhost/wp/wp-content/themes/112410_mayur_color/mydata/script.php?do=get_volunteer_list&venue=london
// http://localhost/wp/wp-content/themes/112410_mayur_color/mydata/script.php?do=get_volunteer_list&venue=manchester
// http://localhost/wp/wp-content/themes/112410_mayur_color/mydata/script.php?do=get_volunteer_list&venue=guildford
// http://localhost/wp/wp-content/themes/112410_mayur_color/mydata/script.php?do=get_volunteer_list&venue=glasgow-edinburgh
