$(document).ready(function(){	

	var overlay_bg_styles = {
			'background' : '#000',
			'filter' : 'alpha(opacity=30)',
			'opacity' : '0.3',
			'-moz-opacity' : '0.3'
		};
	var overlay_border_styles = {
			'background' : '#fff',
			'filter' : 'alpha(opacity=80)',
			'opacity' : '0.8',
			'-moz-opacity' : '0.8'
		};
	var overlay_styles = {
		};
	var overlay_close_styles = {
			'margin-top' : '-30px',
			'background' : 'none',
			'color' : '#000',
			'margin-left' : '-30px',
			'font-size' : '18px'
		};	

	
	
	function show_page() {
		
		$(".image_holder, #winner_holder").dropShadow({
			'left' : 1,
			'top' : 1,
			'blur' : 1,
			'opacity' : 0.3,
			'color' : '#000000'
		}); 
		
		$(".wallpaper a.thumb").click(function () {
			var anchor = $(this).attr("href");
			var link = anchor.split("http://www.soundslikeus.co.nz/staging /");
			if($(this).attr("rel") == "landscape") {
				$(this).overlay(640, 530, 10, 0, overlay_bg_styles, overlay_border_styles, overlay_close_styles, overlay_styles, null);	
				$('#overlay .content').css({
					'background' : 'url(http://www.soundslikeus.co.nz/pic.php?img='+link[1]+'&width=620&height=440) no-repeat 50% 50%',
					'height' : '440px'
				});
			} 
			var download_link = link[1].split("img/wallpaper/1600x1200-");
			$("#overlay .content").html('<table><tr><td><strong>Widescreen:</strong></td><td style="width:100px;"><a href="http://www.soundslikeus.co.nz/pic.php?img=img/wallpaper/1600x1000-'+download_link[1]+'&width=1024" target="_blank">1024 x 640</a></td><td><strong>Normal screen:</strong></td><td><a href="http://www.soundslikeus.co.nz/pic.php?img=img/wallpaper/1600x1200-'+download_link[1]+'&width=800" target="_blank">800 x 600</a></td></tr><tr><td>&nbsp;</td><td><a href="http://www.soundslikeus.co.nz/pic.php?img=img/wallpaper/1600x1000-'+download_link[1]+'&width=1280" target="_blank">1280 x 800</a></td><td>&nbsp;</td><td><a href="http://www.soundslikeus.co.nz/pic.php?img=img/wallpaper/1600x1200-'+download_link[1]+'&width=1024" target="_blank">1024 x 768</a></td></tr><tr><td>&nbsp;</td><td><a href="http://www.soundslikeus.co.nz/pic.php?img=img/wallpaper/1600x1000-'+download_link[1]+'&width=1440" target="_blank">1440 x 900</a></td><td>&nbsp;</td><td><a href="http://www.soundslikeus.co.nz/pic.php?img=img/wallpaper/1600x1200-'+download_link[1]+'&width=1280" target="_blank">1280 x 960</a></td></tr><tr><td>&nbsp;</td><td><a href="http://www.soundslikeus.co.nz/pic.php?img=img/wallpaper/1600x1000-'+download_link[1]+'" target="_blank">1600 x 1000</a></td><td>&nbsp;</td><td><a href="http://www.soundslikeus.co.nz/pic.php?img=img/wallpaper/1600x1200-'+download_link[1]+'" target="_blank">1600 x 1200</a></td></tr></table>');
			return false;
		});
	
	  
	
		var found = $("#main").find(".radios");
		if (found.length == 0) {
		  var path = "radios/radio";
		  var current_url = location.href;
		  var current_radio = current_url.split(path);
		  var this_radio = parseInt(current_radio[1]);
			$('<p><a href="http://www.soundslikeus.co.nz/img/radios/radio'+this_radio+'/pic2.jpg" rel="landscape" class="thumb">View original design</a></p>').appendTo(".radios .col2_3");
			radio_popups();
			$('<div id="flash_player"><span id="flash_movie">Flash player</span></div>').appendTo(".radios .col2_3");
			$('#flash_player').css({'position':'absolute', 'bottom':'25px'});
			var flashvars = {
				mp3:"http://www.soundslikeus.co.nz/mp3/radio"+this_radio+".mp3",
				buttoncolor:"cf343a",
				loadingcolor:"544a3b",
				slidercolor:"e39717",
				autoplay:"1"
			};
			var params = {
				bgcolor:"e9d3b7"
			};
			var attributes = {
				id: "flash_player",
				name: "flash_player"
			};
			swfobject.embedSWF("http://www.soundslikeus.co.nz/swf/player_mp3_mini.swf", "flash_movie", "220", "20", "9.0.0", "http://www.soundslikeus.co.nz/swf/expressInstall.swf", flashvars, params, attributes);		
		}
		
		
		// RADIOS STEPPING	
		if($("#subnavigation.radios").is("div") == true) {
			$.ajax({
			  url: "http://www.soundslikeus.co.nz/inc/subnavigation_radios_all.inc.php",
			  cache: false,
			  success: function(data){
			  	var html_output = data;
			  	$("#subnavigation #radios").remove();
			    $("#subnavigation").html(html_output);
	
			    $("#radios a[href="+document.location.href+"]").addClass("active");
	
					iniImg();
	
					$("#radios img:visible:last").css({'margin-right':'5px'});
					var offset = $("#radios .active").position();
					if(offset != undefined) {
						$("#radios").scrollTo({top:'0px', left:(offset.left - 109)+'px'}, 200);
					}
					
					var next_radio_url = $("#radios .active").next().attr("href");
					if(next_radio_url != undefined) {
						$("#radios").after('<a href="#" class="arrow btn_right"><img src="http://www.soundslikeus.co.nz/img/arrow_right.gif" alt="next page" /></a>');
					}
					
					var prev_radio_url = $("#radios .active").prev().attr("href");
					if(prev_radio_url != undefined) {
						$("#radios").before('<a href="#" class="arrow btn_left"><img src="http://www.soundslikeus.co.nz/img/arrow_left.gif" alt="previous page" /></a>');
					}
				
				  $("#subnavigation.radios .btn_right").click(function(){
				  	if(next_radio_url != undefined) {
					  	var next = next_radio_url.split("http://www.soundslikeus.co.nz/");
							location = '/'+next[1];	
				  	}
				  	return false;
				  });
					$("#subnavigation.radios .btn_left").click(function(){
				  	if(prev_radio_url != undefined) {
					  	var prev = prev_radio_url.split("http://www.soundslikeus.co.nz/");
							location = '/'+prev[1];
						}
						return false;
				  });
	
			  }
			});
		}
		
		
		// 
		$(".vote_detail a.thumb").click(function () {
			var anchor = $(this).attr("href");
			var link = anchor.split("http://www.soundslikeus.co.nz/");
			if($(this).attr("rel") == "landscape") {
				$(this).overlay(640, 480, 10, 0, overlay_bg_styles, overlay_border_styles, overlay_close_styles, overlay_styles, null);	
				$('#overlay .content').css({
					'background' : 'url(http://www.soundslikeus.co.nz/pic.php?img='+link[1]+'&width=620&height=440) no-repeat 50% 50%',
					'height' : '440px'
				});
			} 
			if($(this).attr("rel") == "portrait"){
				$(this).overlay(395, 568, 10, 0, overlay_bg_styles, overlay_border_styles, overlay_close_styles, overlay_styles, null);
				$('#overlay .content').css({
					'background' : 'url(http://www.soundslikeus.co.nz/pic.php?img='+link[1]+'&width=375&height=530) no-repeat 50% 50%',
					'height' : '530px'
				});
			}
			//alert($(this).parent().next().next().attr("class"));
			if($(this).parent().next().next().attr("class") == "design_by") {
				var radio = $("h2 .sIFR-alternate").html();
				var name = $(this).parent().next().next().html();
				$('#overlay .content').html("<table><tr><td><strong>"+radio+" - Designed by "+name+"</strong></td></tr></table>");	
			
			}
			return false;
		});

		$(".vote_detail a.read_more").click(function () {
			var anchor = $(this).attr("href");
			anchor = anchor.split("http://www.soundslikeus.co.nz/");
			anchor = anchor[1];
			if(anchor.indexOf("?") != -1) { 
				anchor = anchor.split("?");
				anchor = anchor[0];
			}
			anchor = "http://www.soundslikeus.co.nz/pages/"+anchor+".php?read_more";
			$(this).overlay(580, 480, 10, 0, overlay_bg_styles, overlay_border_styles, overlay_close_styles, overlay_styles, null);
			$('#overlay .content').css({
				'background' : '#ededed',
				'height' : '402px',
				'padding' : '20px 15px'
			});
			$.ajax({
				  url: anchor,
				  cache: false,
				  success: function(data){
					$('#overlay .content').addClass('votes').html(data);
					$('#overlay .content p.intro').next().css({'font-weight' : 'bold'});
					return false;
				  }
				  
			});
					
			return false;
		});
	 
	
		// COMPETITION STEPPING
		if($("#subnavigation.competition").is("div") == true) {
			var next_comp_url = $("#tuner .active").next().find("a").attr("href");
			if(next_comp_url != undefined) {
				$("#tuner").after('<a href="#" class="arrow btn_right"><img src="http://www.soundslikeus.co.nz/img/arrow_right.gif" alt="next page" /></a>');
			}
			
			var prev_comp_url = $("#tuner .active").prev().find("a").attr("href");
			if(prev_comp_url != undefined) {
				$("#tuner").before('<a href="#" class="arrow btn_left"><img src="http://www.soundslikeus.co.nz/img/arrow_left.gif" alt="previous page" /></a>');
			}
		
		  $("#subnavigation.competition .btn_right").click(function(){
		  	if(next_comp_url != undefined) {
			  	var next = next_comp_url.split("http://www.soundslikeus.co.nz/");
					location = '/'+next[1];	
		  	}
		  	return false;
		  });
			$("#subnavigation.competition .btn_left").click(function(){
		  	if(prev_comp_url != undefined) {
			  	var prev = prev_comp_url.split("http://www.soundslikeus.co.nz/");
					location = '/'+prev[1];
				}
				return false;
		  });  
	  }
		
		$(".thanks").fadeIn("slow").fadeTo(2000, 1).fadeOut("slow");	
	}


	show_page();


	function radio_popups() {
		$(".radios a.thumb").bind("click", function () {
			var anchor = $(this).attr("href");
			var link = anchor.split("http://www.soundslikeus.co.nz/");
			if($(this).attr("rel") == "landscape") {
				$(this).overlay(640, 480, 10, 0, overlay_bg_styles, overlay_border_styles, overlay_close_styles, overlay_styles, null);	
				$('#overlay .content').css({
					'background' : 'url(http://www.soundslikeus.co.nz/pic.php?img='+link[1]+'&width=620&height=440) no-repeat 50% 50%',
					'height' : '440px'
				});
			} 
			if($(this).attr("rel") == "portrait"){
				$(this).overlay(395, 568, 10, 0, overlay_bg_styles, overlay_border_styles, overlay_close_styles, overlay_styles, null);
				$('#overlay .content').css({
					'background' : 'url(http://www.soundslikeus.co.nz/pic.php?img='+link[1]+'&width=375&height=530) no-repeat 50% 50%',
					'height' : '530px'
				});
			}
			return false;
		});
	}
	
	
	



	function iniImg(){
		$("#radios a:not(.active) img, .wallpaper a:not(.active) img").animate({'filter':'alpha(opacity=50)', 'opacity':'0.5', '-moz-opacity':'0.5'}, 400); 

		$("#radios a:not(.active) img, .wallpaper a:not(.active) img").mouseover(function(){  
			$(this).stop().animate({'filter':'alpha(opacity=100)', 'opacity':'1', '-moz-opacity':'1'}, 300); 
		});  
		  
		$("#radios a:not(.active) img, .wallpaper a:not(.active) img").mouseout(function(){  
			$(this).stop().animate({'filter':'alpha(opacity=50)', 'opacity':'0.5', '-moz-opacity':'0.5'}, 300); 
		});
	}
	iniImg();


	$("#radio_rate a").mouseover(function(){
		var rate = $(this).attr('class');
		rate = rate.split('rate');
		$("#radio_rate a:lt("+rate[1]+")").addClass('active');
		$(this).mouseleave(function(){
			$("#radio_rate a:lt("+rate[1]+")").removeClass('active');
		});
	});




    
});

