﻿/*
 * RSP Talent
 *
 * Copyright (c) 2009 Wirepoint Media, LLC (www.wirepointmedia.com)
 *
 * @Author: Chris Cox <chris.cox@wirepointmedia.com> 
 * @Date: 04-14-09
 * @version: 1.0 REV. 04-14-09
 */

$(function(){  

	//Create description container and make ajax call
    $("#modulePage3241924 #content").prepend("<div id='desc' style='display:none'></div>");
	$("#modulePage3241924 #desc").load("/image-library/image-sliders/ #content .description", function(data) {});

	//Create thumbnail container to load images into and make ajax call
	$("#modulePage3241924 #content"). prepend("<div id='thumbs' style='display:none'></div>");
	$("#modulePage3241924 #thumbs").load("/image-library/image-sliders/ #content img", function(data) {

		//Filter out gallery thumbnail images    
		$("#thumbs img").each(function(i){
		  
			//Get attributes
			var desc = $("#content #desc .description:eq(" + i + ") p").text();
			var filename = $(this).attr("title");
			var id = $(this).attr("id").replace("picture", "").replace("-img", "");     
			var imgUrl = "/picture/" + filename + "?pictureId=" + id; 
			var thumbUrl = imgUrl + "&asThumbnail=true";   

			// add images to slider
			$('#slideshow').append("<img src='" + imgUrl + "' width='850' height='306' title='" + filename + "' alt='" + desc + "'</img>");
		
		});

        //Add title & desc if only one image
        if ( $("#thumbs").length == 1 ){
            $('#textWrapper #slideShowHeader').html( $('#slideshow img').attr('title'));
            $('#textWrapper #slideShowText').html( $('#slideshow img').attr('alt'));
        }; 

		$('#slideshow').cycle({ 
			fx:     'zoom',
			sync:    true,
			speed:   400, 
			timeout: 7000, 
			pager:  '#nav',
			pagerEvent: 'mouseover', 
			pauseOnPagerHover: true,
			before:  onBefore, 
			after:   onAfter 
		}); 

		function onBefore() { 
			$('#textWrapper').fadeOut("fast"); 
		} 

		function onAfter() { 
			$('#textWrapper').fadeIn("slow");
			$('#textWrapper #slideShowHeader').html(this.title);
			$('#textWrapper #slideShowText').html(this.alt);
			//$('#textWrapper a').attr("href", this.name);
		}		
	});

    
    //Create description container and make ajax call
    $("#modulePage3241924 #content").prepend("<div id='descFeaturedEvent' style='display:none'></div>");
	$("#modulePage3241924 #descFeaturedEvent").load("/image-library/featured-booked-event-by-rsp/ #content .description", function(data) {});

	//Create thumbnail container to load images into and make ajax call
	$("#modulePage3241924 #content"). prepend("<div id='thumbsFeaturedEvent' style='display:none'></div>");
	$("#modulePage3241924 #thumbsFeaturedEvent").load("/image-library/featured-booked-event-by-rsp/ #content img", function(data) {

		 //Get attributes
		var desc = $("#content #descFeaturedEvent .description:first p").text();
		var filename = $("#thumbsFeaturedEvent img").attr("title");
		var id = $("#thumbsFeaturedEvent img").attr("id").replace("picture", "").replace("-img", "");     
		var imgUrl = "/picture/" + filename + "?pictureId=" + id; 
		var thumbUrl = imgUrl + "&asThumbnail=true";   

		// add images to slider
                $('#grid1 .flyerImage').attr("src", imgUrl);
                $('#grid1 .flyerTitle').text(filename);
                $('#grid1 .flyerText').text(desc);

	});

    //Create description container and make ajax call
    $("#modulePage3241924 #content").prepend("<div id='descFeaturedClient' style='display:none'></div>");
	$("#modulePage3241924 #descFeaturedClient").load("/image-library/featured-client/ #content .description", function(data) {});

	//Create thumbnail container to load images into and make ajax call
	$("#modulePage3241924 #content"). prepend("<div id='thumbsFeaturedClient' style='display:none'></div>");
	$("#modulePage3241924 #thumbsFeaturedClient").load("/image-library/featured-client/ #content img", function(data) {

		 //Get attributes
		var desc = $("#content #descFeaturedClient .description:first p").text();
		var filename = $("#thumbsFeaturedClient img").attr("title");
		var id = $("#thumbsFeaturedClient img").attr("id").replace("picture", "").replace("-img", "");     
		var imgUrl = "/picture/" + filename + "?pictureId=" + id; 
		var thumbUrl = imgUrl + "&asThumbnail=true";   

		// add images to slider
        $('#grid2 .flyerImage').attr("src", imgUrl);
        $('#grid2 .flyerTitle').text(filename);
        $('#grid2 .flyerText').text(desc);

	});

    //Add drop down panel
    $("#pageBody").prepend("<div id='panelWrapper'><div id='panel'><div id='panelTop'></div><div id='panelSubmit'></div><div id='panelBottom'></div></div></div>");

    //Relocate contact form widget
    $("#panelTop").append($("#moduleContentWrapper3246635"));
    $("#panelWrapper").hide();

    //Relocate What's Happening widget
    $(".grid #grid3").append($("#sectionContent1653093"));

    //Relocate vert nav bar on blog details
    $("#pageBody:has('.journal-entry-navigation') #sectionContent1653093").hide();
    $("#pageBody:has('.journal-entry-navigation') #sidebar1Wrapper").css("margin-top", "80px");


    //Set search bar
    $("#moduleContentWrapper3251692 input.text").defaultvalue("type search keyword");

    //global
    var isContactFormShowing = false;
    var isContactFormSaving = false;

    //Contact Us click function 
    if (detectBrowser()){
        $("#navigationTop-moduleLink3202529").click(function(){  
            $("#panelWrapper").show(); 
            $("#fade").fadeIn("slow");
            $("#panel").animate({top: 0 }, 200 );
            $("#panel").effect("bounce",{times:1.5, direction:'up', distance:30},300);
            isContactFormShowing = true;
            return false;
        });
    };


    //Close drop down form
    $("#panelBottom").click(function(){
        if (isContactFormShowing == true){
            closeDropDown();
            isContactFormShowing = false;
        };    
    });

    //Contact form submit action
    $("#panelSubmit").click(function(){  
        if (isContactFormShowing == true){
            isContactFormSaving = true;
            theForm3246635.submitCustomForm();      
            closeDropDown();
            isContactFormShowing = false;      
        };
    });

    function closeDropDown(){
        $("#fade").fadeOut("fast");
        $("#panel").animate({ top:-408 }, 500, function(){
            $("#panelWrapper").hide();
            if (isContactFormSaving == true){
                //refresh page
                window.location = "/contact-us?success=true"
                //history.go(0);
            };
            isContactFormSaving = false;
        });
    };

    function detectBrowser() {
        var browser=navigator.appName;
        if (browser == "Microsoft Internet Explorer") { 
            return false;
        } else {
            return true;
        }
    };

});