$(document).ready(function() {
	youtubeZfix();
        faceBook();
        topMenus();
	linksEffect();
	draw_clock();
	next_service();
	//radio_info();
	dropDown_menu();
	zoomImages();

      $("a[rel='preview']").colorbox();
      $("a[rel='frame-preview']").colorbox({iframe:true, fixed:true, rel:'nofollow', innerWidth:807, innerHeight:430}); 

      /*$.embedquicktime({
      jquery: '/js/alpha/libraries/jquery-1.3.2.min.js',
      plugin: '/js/alpha/libraries/jquery.embedquicktime.js'
    });*/


});

function youtubeZfix(){

var url = $('#content iframe').attr("src")

$('#content iframe').attr("src",url+"?wmode=transparent")

}

function faceBook(){

     (function(d, s, id) {
          var js, fjs = d.getElementsByTagName(s)[0];
          if (d.getElementById(id)) {return;}
          js = d.createElement(s); js.id = id;
          js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1";
          fjs.parentNode.insertBefore(js, fjs);
        }
        (document, 'script', 'facebook-jssdk'));
}

function topMenus(){
    	for ($i = 1; $i < 5; $i++) {
		$("#topIcons #img"+$i).css( {
			'right' : (27 * $i) + "px"
		});
	}

    $("a[rel='preview']").colorbox();
}



function linksEffect() {
	$('#firstFrame img, #secondFrame img, #lower-middle img')
			.hover(function() {
				$(this).css( {
					border : "yellow outset"
				});
			}, function() {
				$(this).css( {
					border : "none"
				});
			});
}

function draw_clock() {
	canvas = Raphael("mainclock", 181, 180);
	// var clock = canvas.circle(100, 100, 70);

	// canvas.rect(65, 115, 72, 20, 10).attr( {
	// "fill" : "#ffffff",
	// "stroke-width" : "2"
	// });

	// clock.attr( {
	// "fill" : "#eaeaea",
	// "stroke" : "#eaeaea",
	// "stroke-width" : "15"
	// })
	var hour_sign;
	for (i = 0; i < 12; i++) {
		var start_x = 100 + Math.round(60 * Math.cos(30 * i * Math.PI / 180));
		var start_y = 100 + Math.round(60 * Math.sin(30 * i * Math.PI / 180));
		var end_x = 100 + Math.round(70 * Math.cos(30 * i * Math.PI / 180));
		var end_y = 100 + Math.round(70 * Math.sin(30 * i * Math.PI / 180));
		// hour_sign = canvas.path("M" + start_x + " " + start_y + "L" + end_x
		// + " " + end_y);
	}

	// var c = 95, f = 95, e = 10
	//
	// canvas.g.arrow(c, f, 10).rotate(-90);

	hour_hand = canvas.path("M95 95L95 65");
	hour_hand.attr( {
		stroke : "#000000",
		"stroke-width" : 4
	});
	minute_hand = canvas.path("M95 95L90 52");
	minute_hand.attr( {
		stroke : "#000000",
		"stroke-width" : 2
	});
	second_hand = canvas.path("M95 95 L100 40");
	second_hand.attr( {
		stroke : "#000000",
		"stroke-width" : 1
	});

	canvas.text(92, 113, getService()).attr( {
		"font-size" : "11px",
		"fill" : "black",
		"font-weight" : "bold"
	});
	// canvas.text(100, 145, "London").attr( {
	// "font-size" : "11px",
	// "fill" : "black"
	// });

	// img = new Image();
	//
	// img.src = "/files/library/images/pointer.png";
	//
	// pointer = canvas.image(img.src, 95, 95, 14, 41);

	var pin = canvas.circle(95, 95, 3);
	pin.attr("fill", "#000000");
	update_clock()
	setInterval("update_clock()", 1000);
}

function update_clock() {
	var now = new Date();
	var hours = now.getHours();
	var minutes = now.getMinutes();
	var seconds = now.getSeconds();
	hour_hand.rotate(30 * hours + (minutes / 2.5), 95, 95);
	minute_hand.rotate(6 * minutes, 95, 95);
	second_hand.rotate(6 * seconds, 95, 95);
}

function getService() {
	var now = new Date();
	var service;
	var today = new Date().getDay();
	var hours = now.getHours();
	var minutes = now.getMinutes();

	var now = new Date().getHours();
	if (today > 0 && today < 6) {
		if (today == 5 && hours <= 19) {
			service = "Hoje 7:30PM";
		}
                else if (today == 5 &&( (hours >= 21 && minutes > 30) || hours >= 22)) {
			service = "SAB 7:30PM";
		} else if (today == 5 && ((hours >= 19) && (hours <= 22))) {
			if (hours == 19 && minutes < 30) {
				service = "Hoje 7:30PM";
			} else if (hours == 21 && minutes > 30) {
				service = "SAB 7:30PM";
			} else
				service = "AGORA!";
		}  else
			service = "FRI 7:30PM";
	} else
		switch (today) {
		// today is saturday
		case 6:
			if ((hours >= 21 && minutes > 30) || hours >= 22) {
				service = "DOM 3PM";
			} else if (((hours >= 19) && (hours <= 22))) {
				if (hours == 19 && minutes < 30) {
					service = "Hoje 7:30PM";
				} else if (hours == 21 && minutes > 30) {
					service = "DOM 3PM";
				} else
					service = "AGORA!";
			} else
				service = "Hoje 7:30PM";
			break;
		// today is sunday
		case 0:
			if ((hours >= 15 && hours < 17) || (hours >= 19 && hours <= 22)) {
				if (hours == 21 && minutes > 30) {
					service = "FRI 7:30PM";
				} else
					service = "AGORA!";
			} else if ((hours < 15)) {
				service = "Hoje 3PM";
			} else if (hours >= 17 && hours <= 19) {
				service = "Hoje 7PM"
			} else
				service = "DOM 3PM";
			break;
		default:
			service = "DOM 7PM";
		}

	return service;
}

function next_service() {
	xOffset = 10;
	yOffset = 30;

	var info;

	switch (getService()) {
	case "FRI 7:30PM":
		info = "Sexta-Feira às 7:30pm";
		break;
	case "SAB 7:30PM":
		info = "Sábado às 7:30pm"
		break;
	case "DOM 3PM":
		info = "Doming às 3 da tarde"
		break;
	case "DOM 7PM":
		info = "Doming às 7pm"
		break;
	case "Hoje 3PM":
		info = "Hoje às 3 da tarde"
		break;
	case "Hoje 7:30PM":
		info = "Hoje às 7 e meia da noite"
		break;

	case "Hoje 7PM":
		info = "Hoje às 7 da noite"
		break;

	case "AGORA!":
		info = "ACONTECENDO AGORA / AO VIVO & ONLINE!"
	}
	$("#mainclock").hover(
			function(e) {
				this.t = this.title;
				this.title = "";
				var c = (this.t != "") ? "<br/>" + this.t : "";
				$("body").append(
						"<p id='preview'>Próximo culto<br/>" + info + c
								+ "</p>");

				$("#preview").css("top", (e.pageY - xOffset) + "px").css(
						"position", ("absolute")).css("left",
						(e.pageX + yOffset) + "px").fadeIn("slow").css( {
					'text-align' : 'center',
					'font-weight' : 'bold',
					'font-family' : 'arial'
				})

			}, function() {
				this.title = this.t;
				$("#preview").remove();
			});
	$("#mainclock").mousemove(
			function(e) {
				$("#preview").css("top", (e.pageY - xOffset) + "px").css(
						"left", (e.pageX + yOffset) + "px");
			});
}

function radio_info(){
			$("#music").hover(
			function(e) {
				this.t = this.title;
				this.title = "";
				var c = (this.t != "") ? "<br/>" + this.t : "";
				$("body").append(
						"<p id='preview'>Radio Alpha now playing<br/>" + c
								+ "</p>");

				$("#preview").css("top", ((e.pageY - xOffset)) + "px").css(
						"position", ("absolute")).css("left",
						((e.pageX + yOffset)) + "px").fadeIn("slow").css( {
					'text-align' : 'center',
					'font-weight' : 'bold',
					'color' : 'blue',
					'font-family' : 'arial',
					'font-size' : '20px'
				})

			}, function() {
				this.title = this.t;
				$("#preview").remove();
			});
	$("#music").mousemove(
			function(e) {
				$("#preview").css("top", (e.pageY - xOffset) + "px").css(
						"left", (e.pageX + yOffset) + "px");
			});
			
			
			
	//stop start radio
	$("#music").toggle(
  function (e) {
	  e.preventDefault();
    $("#radioAlpha").remove();
  },
  function (e) {
	  //e.preventDefault();
    //$('body').append('<object id="radioAlpha"><param name="FileName" value="http://87.117.203.166:12175" /><param name="AutoStart" value="True" /><param name="ShowStatusBar" value="True" /><param name="DefaultFrame" value="mainFrame" /><embed type="application/x-mplayer2"pluginspage = "http://www.microsoft.com/Windows/MediaPlayer/"src="http://87.117.203.166:12175"HIDDEN=TRUE></embed></object>')
  }
  
);




}
function zoomImages() {

        var sections = new Array("#shop", "#news", "#music", "#bible");
        var sectionsWidth = new Array(69, 40, 70, 136);
        var sectionsMaxSize = new Array(10, 10, 10, 15);


        for(var i = 0; i < sections.length; i++){

       $(sections[i]).Fisheye(
				{
					maxWidth: sectionsMaxSize[i],
					items: 'div',
					itemsText: 'span',
					container: '.fisheyeContainter',
					itemWidth: sectionsWidth[i],
					proximity: 15,
                                        alignment : 'left',
                                        valign: 'bottom',
					halign : 'center'
				}
                              ).hover(function() {
                                      $(".fisheyeContainter", this).css({
                                     'z-index' : '999'
                              })
                                      $(".fisheyeContainter span", this).css({
                                        
                                      })
                          }, function (){
                                      $(".fisheyeContainter", this).css({
                                     'z-index' : '1'
                              })
                          } )
        }
        

}
function dropDown_menu() {
	$('.dropdown').each(function() {
		$(this).parent().eq(0).hoverIntent( {
			timeout : 200,

			over : function() {
				var current = $('.dropdown:eq(0)', this);
				current.slideDown(150);
			},
			out : function() {
				var current = $('.dropdown:eq(0)', this);
				current.fadeOut(200);
			}
		});
	});

	$('.dropdown a').hover(function() {
		$(this).stop(true).animate( {
			paddingLeft : '10px'
		}, {
			speed : 100,
			easing : 'easeOutBack'
		});
	}, function() {
		$(this).stop(true).animate( {
			paddingLeft : '0'
		}, {
			speed : 100,
			easing : 'easeOutBounce'
		});
	});

	pic1 = new Image(310, 672);
	pic1.src = "images/dropdown.png";

	pic2 = new Image(4, 40);
	pic2.src = "images/dropselectionleft.png";

	pic3 = new Image(394, 40);
	pic3.src = "images/dropselectionright.png";

}

