// NAVIGATION
function nav() {
	// show sub menu on hover
	$(".n-item a").mouseover(function(){
    	$(".n-sub").hide();
    	var item = $(this).siblings(".n-sub");
		var itemPositionTop = $(this).parent().position().top + 60 +"px";
		var itemPositionLeft = $(this).position().left +"px";
		item.css({"top":itemPositionTop,"left":itemPositionLeft});
		item.show();
    }).mouseout(function(){
    	$(this).siblings(".n-sub").hide();
    });
        
	// keep main menu on "on" state when mouse is inside sub menu
	$(".n-sub").mouseover(function(){
    	$(this).show();
    	$(this).siblings("a").addClass("current");
    }).mouseout(function(){
    	$(this).hide();
    	$(this).siblings("a").removeClass("current");
    });

	// hide sub-menu on 
	//$("#header").mouseover(function(){
    //	$("body .n-sub").hide();
    //}).mouseout(function(){
    //});
}

// FLASH HEADLINES
function headlines() {
 	$(".blog").append("<h1>Blog</h1>");
	$("#content h2:first").css("margin-top","20px");
 	$("h1").prependTo($("#wrapper")).wrap('<div id="header-title"/>');
 	$("#header").prependTo($("#wrapper"));
	if(typeof sIFR == "function"){
		sIFR.replaceElement(named({sSelector:"h1", sFlashSrc:"/wp-content/themes/newstogram/flash/apexnewmedium.swf", sColor:"#344182", sWmode:"transparent"}));
		sIFR.replaceElement(named({sSelector:"h2", sFlashSrc:"/wp-content/themes/newstogram/flash/apexnewmedium.swf", sColor:"#344182", sWmode:"transparent"}));
		sIFR.replaceElement(named({sSelector:"#primary h3", sFlashSrc:"/wp-content/themes/newstogram/flash/apexnewbold.swf", sColor:"#333333", sWmode:"transparent"}));
		sIFR.replaceElement(named({sSelector:"#secondary h3", sFlashSrc:"/wp-content/themes/newstogram/flash/apexnewbold.swf", sColor:"#ffffff", sWmode:"transparent"}));
		sIFR.replaceElement(named({sSelector:"#footer-widget-area h3", sFlashSrc:"/wp-content/themes/newstogram/flash/apexnewbold.swf", sColor:"#ffffff", sWmode:"transparent"}));
		sIFR.replaceElement(named({sSelector:"#primary #archives-2 h3", sFlashSrc:"/wp-content/themes/newstogram/flash/apexnewmedium.swf", sColor:"#ffffff", sWmode:"transparent"}));
		sIFR.replaceElement(named({sSelector:"#primary #linkcat-2 h3", sFlashSrc:"/wp-content/themes/newstogram/flash/apexnewmedium.swf", sColor:"#ffffff", sWmode:"transparent"}));
		sIFR.replaceElement(named({sSelector:"#content h4", sFlashSrc:"/wp-content/themes/newstogram/flash/apexnewbook.swf", sColor:"#333", sWmode:"transparent"}));
		sIFR.replaceElement(named({sSelector:"#content h5", sFlashSrc:"/wp-content/themes/newstogram/flash/apexnewmedium.swf", sColor:"#344182", sWmode:"transparent"}));
	};
}

// INTROS
function intros() {
	$(".intro-flash").insertAfter($("#header"));
}

// SIDEBAR FUNCTIONS (SHOW DIFFERENT SIDEBARS ON DIFFERENT PAGES)
function sidebar() {	
	$("#primary #text-5").addClass("nomargin");
	$("#secondary .xoxo li:last").addClass("nomargin");
	$("#footer-widget-area #first .xoxo li:last").addClass("nomargin");
	$("#footer-widget-area #second .xoxo li:last").addClass("nomargin");
	$(".blog #linkcat-2").remove().prependTo("#primary");
	$(".blog #archives-2").remove().prependTo("#primary");
	$(".archive #linkcat-2").remove().prependTo("#primary");
	$(".archive #archives-2").remove().prependTo("#primary");
	$(".single #linkcat-2").remove().prependTo("#primary");
	$(".single #archives-2").remove().prependTo("#primary");
	$(".flashmovie").remove().appendTo("#flash-container");
}

// FORMS (ADD TEXT TO FIELDS)
function forms() {
	$(".wpcf7 .your-name input").val("Your Name");
	$(".wpcf7 .your-email input").val("Email address");
	$(".wpcf7 .your-site input").val("Your Site's URL");
	$(".wpcf7 .textarea-687 textarea").val("Comments");
	//$("#primary input.wpcf7-submit").replaceWith('<input type="image" src="/wp-content/themes/newstogram/images/button-send.gif>');
	//$("#footer input.wpcf7-submit").replaceWith('<input type="image" src="/wp-content/themes/newstogram/images/button-send-02.gif>');
}

// LIST
function list() {
	$("#items-list li:odd").after('<div class="cb"/>');
}

// HOME SLIDESHOW

function homeSlideshow() {
	$("#slideshow-home").cycle({
		fx:'fade',
		timeout:5000
	});
}

// HOME FLASH
function homeFlash() {
	// for flash slideshow
	var windowH = $(window).height() - 166;
	var windowW = $(window).width();
	if (windowH < 580) {windowH=580};
	if (windowW < 970) {windowW=970};
	$(".home #main").height(windowH);
	$(".home #wrapper").width(windowW);
	$(".home #holder").height(windowH);
	// for javascript slideshow
	var imgH = $(window).width() / 2;
	$("#slideshow-home").width($(window).width());
	$("#slideshow-home div").width($(window).width());
	$("#slideshow-home img").width($(window).width());
	$("#slideshow-home img").height(imgH);
	// for modules
	var posT = $(window).height() - 300;
	var posL = ($(window).width() - 880)/2;
	if (posL < 0) {posL=0};
	$(".home #footer-widget-area").css("top",470);
	$(".home #footer-widget-area").css("left",posL);
	//change on resize
	$(window).resize(function() {
		var windowH = $(window).height() - 166;
		var windowW = $(window).width();
		if (windowH < 580) {windowH=580};
		if (windowW < 970) {windowW=970};
		var posT = $(window).height() - 300;
		var posL = ($(window).width() - 880)/2;
		$(".home #main").height(windowH);
		$(".home #wrapper").width(windowW);
		$(".home #holder").height(windowH);
		var imgH = $(window).width() / 2;
		$("#slideshow-home").width($(window).width());
		$("#slideshow-home div").width($(window).width());
		$("#slideshow-home img").width($(window).width());
		$("#slideshow-home img").height(imgH);
		if (posL < 0) {posL=0};
		$(".home #footer-widget-area").css("top",470);
		$(".home #footer-widget-area").css("left",posL);
	});
}
         
// MAP

function GetMap() {
	var map = null;
	var myBingLat = 26.0106; 
	var myBingLng = -80.1837;
	var myBingZoom = 9;
	var myBirdZoom = 1;
	map = new VEMap('myMap');         
	map.LoadMap();
	var myBingWaypoint = new VELatLong(myBingLat,myBingLng);
	map.SetCenterAndZoom(myBingWaypoint, myBingZoom);
	map.SetMapStyle(VEMapStyle.Birdseye);
	map.SetBirdseyeScene(myBingWaypoint,VEOrientation.North,myBirdZoom);
	//map.AddPushpin(myBingWaypoint);
}   



  
$(document).ready(function(){
	nav();
	headlines();
	intros();
	sidebar();
	forms();
	list();
	homeFlash();
	homeSlideshow();
	GetMap();
});
