var oRequestHandlers = new $A();
var app_debug = false; //this variable is used for logging in all application -- false=no logging , true=logging.
var log_clientside_exceptions = true; //for controlling client side exception logging on/off.

var show_custom_messages = false;

var domain = location.protocol + "//" + location.host;
requesthandler = new RequestHandler();
requesthandler.type = "mapservice";

oRequestHandlers[0] = requesthandler;

function contentTabsSwitch(link, contentId) {
    var li = link.parentNode;

    if(li.className != "selected") {

        var lis = li.parentNode.getElementsByTagName("LI");

        for(var i = 0; i < lis.length; i++) {
            lis[i].className = "";

        }

        var contentSections = li.parentNode.parentNode.getElementsByTagName("DIV");
    
        for(i = 0; i < contentSections.length; i++) {
                if(contentSections[i].className == "siteContentTab") {
                    contentSections[i].style.display = "none";
                }
        }

        li.className = "selected";
        $(contentId).show();

    }

    link.blur();

}

function update_counts(){
	if ($('user_latest_count').innerHTML<0){
		$('user_latest_count').update('0');
	}
	
	if ($('user_video_count').innerHTML<0){
		$('user_video_count').update('0');
	}
	
	if ($('user_image_count').innerHTML<0){
		$('user_image_count').update('0');
	}
	
	if ($('user_blog_count').innerHTML<0){
		$('user_blog_count').update('0');
	}
	
	if ($('user_event_count').innerHTML<0){
		$('user_event_count').update('0');
	}
	
	if ($('user_comment_count').innerHTML<0){
		$('user_comment_count').update('0');
	}	
	
	if ($('user_history_count').innerHTML<0){
		$('user_history_count').update('0');
	}
	
	if ($('user_bookmark_count').innerHTML<0){
		$('user_bookmark_count').update('0');
	}
}

function new_change_filter(filter_list,selected_filter,widget_name)
{
    for(i=0; i<filter_list.length; i++)
    {
        if (selected_filter == filter_list[i])
        {
            $(widget_name + "_plan_" + filter_list[i]).show();
            $(widget_name + "_" + filter_list[i]).hide();
        }
        else
        {
            $(widget_name + "_plan_" + filter_list[i]).hide();
            $(widget_name + "_" + filter_list[i]).show();
        }
    }
}

function change_filter(request_handler, widget_name, type, category, order) {
    var sel = "";
    var desel = "";
    
    switch(order)
    {
        case 1:
            sel = "popular";
            desel = "recent";
            break;
        
        case 2:
            sel = "recent";
            desel = "popular";
            break;
    }

    $(widget_name + "_plan_" + sel).show();
    $(widget_name + "_" + sel).hide();

    $(widget_name + "_plan_" + desel).hide();
    $(widget_name + "_" + desel).show();

    request_handler.setParameters('1', type, category, sel);
    //request_handler.update("all");
    //reloadFlash();
    return false;
}

function toggleLinks(link, id) {
    if(link.className != "selected") {
        var links = document.getElementById(id).getElementsByTagName('A');

        for(var i = 0; i < links.length; i++) {
            links[i].className = "";
        }

        link.className = "selected";
        link.blur();
        return true;
    }

    link.blur();
    return false;
}

function loadEditEventMaster(id) {

    var event = document.getElementById("update_event_" + id);
    var master = document.getElementById("update_event_master");


    master.event_id.value = id;
    master.title.value = event.title.value;
    master.summary.value = $('edit_summary_'+id).innerHTML;
    master.tag_list.value = event.tag_list.value;

    // check to see if we need to load the list of countries up
    if(document.getElementById("event_geo_country_1").options.length <= 1) {
        loadGeolocations("event_geo_country_1","event_geo_state_1");
    }

    changeSelectBox("category_master", event.category.value);
    changeSelectBox("event_geo_country_1", event.country.value);

    document.getElementById('event_geo_city_1').value = event.city.value;

    if(event.country.value == "United States of America") {
        document.getElementById('event_state_field_geo_1').style.display = "";
        changeSelectBox("event_geo_state_1", event.state.value);
    } else {
        document.getElementById('event_state_field_geo_1').style.display = "none";
    }

}

function loadEditBlogMaster(id) {
    
   // var blog = document.getElementById("edit_blog_" + id);
   // var master = document.getElementById("edit_blog_form_profile_master");

   // alert('test')
}


function loadGeolocations(countries_id, states_id) {


    if(document.getElementById("geolocation_countries") && document.getElementById(countries_id)) {
        var countries = document.getElementById(countries_id);
        var countriesMaster = document.getElementById("geolocation_countries");

        countries.options.length = 0;
        for(i = 0; i < countriesMaster.options.length; i++) {
              countries.options[countries.options.length] = new Option(countriesMaster.options[i].innerHTML, countriesMaster.options[i].value);
        }
    }

    if(document.getElementById("geolocation_states") && document.getElementById(states_id)) {
        var states = document.getElementById(states_id);
        var statesMaster = document.getElementById("geolocation_states");

        states.options.length = 0;        
        for(i = 0; i < statesMaster.options.length; i++) {
            states.options[states.options.length] = new Option(statesMaster.options[i].innerHTML, statesMaster.options[i].value);
        }
    }


}



function changeSelectBox(select_id, selected_index) {
    var select = document.getElementById(select_id);

    for(var i = 0; i < select.options.length; i++) {
        select.options[i].selected = (select.options[i].value == selected_index ? true : false);
    }
}

    function showHoverContext(type, obj, offsetType, superOffsetX, superOffsetY, noAdjust, staticMsgHolder, useId, className) {

        // this function will search the DOM for the right hover content unless you tell it to use a
        // staticMsgHolder ID or a useId ID 

        if(hoverContextLocked) {  // if it's locked then we can't open a new one or close the old one without a special click
            return;
        }

        if(offsetType == "RedBox") {
            hcId = offsetType;
        } else {
            hcId = "";
        }

        if(className != "") {
            className = "hoverContextBox " + className;
        } else {
            className = "hoverContextBox";
        }        

        if($('hoverContextBox'+hcId)) {

            pauseHoverContextHide();
            var hc = $('hoverContextBox'+hcId);
            hc.className = className;

            if( hoverContextBackupObj != "") {
                hoverContextBackupObj.innerHTML = hc.innerHTML;  // restore content back to where it came from
                hoverContextBackupObj = "";
            }

            if(!superOffsetX) {
                superOffsetX = 0;
            }
            if(!superOffsetY) {
                superOffsetY = 0;
            }

            // makes sure ALT/TITLE hover text doesn't show on the thumb
            var imgThumb = obj.getElementsByTagName("IMG")[0];
            var aThumb = obj.getElementsByTagName("A")[0];

            if(imgThumb) {
                imgThumb.title = "";
                imgThumb.alt = "";
            }
            if(aThumb) {
                aThumb.title = "";
            }

            var offsetX = 0;
            var offsetY = 0;

            // set position offsets according to the type passed in
            // this has some logic behind it so that it won't show the box off the view section
            if(type == "bottomLeft") {
                offsetY = obj.offsetHeight + 2;
                // if the obj isn't too far right to show the right hoverbox, set it to go left
                if(obj.parentNode.offsetLeft + obj.offsetWidth + 200 > obj.parentNode.parentNode.offsetWidth && !noAdjust) {
                    offsetX = -266 + obj.offsetWidth;
                } 
            } else if(type == "bottomRight") {
                offsetY = obj.offsetHeight + 2;
                // if the obj isn't too far left to show the left hoverbox, then stay right
                if(obj.parentNode.offsetLeft > 200 && !noAdjust) {
                    offsetX = -266 + obj.offsetWidth;
                }
            } else if(type == "topRight") {
                // if the obj is out of view
                if(obj.parentNode.offsetTop+obj.parentNode.parentNode.parentNode.offsetTop + obj.offsetHeight > obj.parentNode.parentNode.parentNode.parentNode.offsetHeight) {
                    hc.style.display = 'none';
                    return; // don't show
                }
                offsetX = obj.offsetWidth + 2;
            }


            var coords = "";
            // special offset mode for when the content is in a redbox instead of the page
            // a slightly different way of offsetting the hover box since the redbox is outside of the #wrapper
            if(offsetType == "RedBox") {
                coords = SpareTools.getOffsetFromRedbox(obj.parentNode);
            } else {
                coords = SpareTools.getOffsetFromWrapper(obj.parentNode);
            }

            hc.innerHTML = "";
            if(staticMsgHolder) {
                hc.innerHTML = "<span class=\"staticHoverMsg\">" + $(staticMsgHolder).innerHTML + "</span>";
            } else if(useId) {
                hc.innerHTML = $(useId).innerHTML;
            } else {
                var divs = obj.parentNode.getElementsByTagName("DIV");
                for(var i = 0; i < divs.length; i++) {
                    if(divs[i].className == "hoverContent") {
                        hc.innerHTML = divs[i].innerHTML;

                        hoverContextBackupObj = divs[i];                // save the dom obj we're getting content from
                        hoverContextBackupObj.innerHTML = "";           // nuke the current content to prevent ID conflict
                                                                        // we'll restore the content into here later
                        break;
                    }
                }
            }
           // alert(coords['y'] + " " + " " + offsetY + " " + superOffsetY + " " + coords['x'] + " " + offsetX + " " + superOffsetX);
           SpareTools.moveObject(hc, coords['y']+offsetY+superOffsetY, coords['x']+offsetX+superOffsetX);

            //SpareTools.moveObject(hc, 5, 5);

            hc.style.display = "block";
            hc.style.zIndex = 500;
        }
    }

    function lockHoverContext(link) {
        hoverContextLocked = true;
        
    }

    function unlockHoverContext(id) {
        hoverContextLocked = false;

        if(id == undefined) {
            id = "";
        }

        hideHoverContext(id);
    }

    var hoverContextBackupObj = "";
    var hoverContextLocked = false;
    var hideHoverTimeout = false;
    function hideHoverContext(id) {
        if(hoverContextLocked) {
            return;
        }

        if(id == undefined) {
            id = "";
        }

        if($('hoverContextBox'+id)) {
            hideHoverTimeout = true;
            setTimeout("if(hideHoverTimeout) { $('hoverContextBox" + id + "').hide(); hoverContextBackupObj.innerHTML = $('hoverContextBox" + id + "').innerHTML; hoverContextBackupObj = ''; }", 100);
        }
    }

    function pauseHoverContextHide() {
        hideHoverTimeout = false;
    }


    function flashPutHref(href) { location.href = href; }       // hack to get rid of JS errors
    function flashPutTitle(title) {  document.title = title; }  // hack to get rid of JS errors
	
	
	function writeAllMediaPlayer(player, xml_file, trackUrl, width, height, div_to_populate, caption, index) {
		var so = new SWFObject(player, "slideshowpro", width, height, 9, "#ffffff");    
		so.useExpressInstall(domain + "/expressinstall.swf");
	    so.addParam("allowFullScreen","true"); 
	    so.addVariable("initialURL", escape(document.location));
	    so.addVariable("xmlFile", xml_file);
	    so.addParam("wmode", "transparent");
	
		//	$('video').innerHTML = '';
		//  so.write("video");
		
		// [ryan 1-5-9]
		// this parameter is no longer really optional, every existing place in the code that calls it uses it,
		// but the legacy behavior is this, so I'm leaving it in for now
	    if (div_to_populate != null && typeof(div_to_populate) == 'undefined') {
	    	div_to_populate = 'event_images';
	    }
	    
		$(div_to_populate).innerHTML = '';
	    so.write(div_to_populate);		

		if(caption != null && typeof(caption) != 'undefined'){
			$('mediaDesc').innerHTML = caption;
		}
		
		// [ryan 1-5-9]
		// this is only used on big media player, can't really enforce that other sizes don't call it...
		// still ought to be safe like this
		if(index != null && typeof(index) != 'undefined'){
			video_index_found = index;
			show_video_next_prev();
		}
				
		urchinTracker(trackUrl);
	
		return false;		
	}
	/*
	function writeMediaPlayer(player, xml_file, trackUrl, caption){
		
		var so = new SWFObject(player, "slideshowpro", "480", "385", 9, "#ffffff");    
		so.useExpressInstall(domain + "/expressinstall.swf");
	    so.addParam("allowFullScreen","true"); 
	    so.addVariable("initialURL", escape(document.location));
	    so.addVariable("xmlFile", xml_file);
	    so.addParam("wmode", "transparent");
		$('event_images').innerHTML = '';
	    so.write("event_images");
		
		if(typeof(caption) != 'undefined'){
			$('mediaDesc').innerHTML = caption;
		}
		
		urchinTracker(trackUrl);
	
		return false;
	
	}
	
	function writeLandingPageMediaPlayer(player, xml_file, trackUrl, caption){
		var so = new SWFObject(player, "slideshowpro", "292", "235", 9, "#ffffff");    
		so.useExpressInstall(domain + "/expressinstall.swf");
	    so.addParam("allowFullScreen","true"); 
	    so.addVariable("initialURL", escape(document.location));
	    so.addVariable("xmlFile", xml_file);
	    so.addParam("wmode", "transparent");
		$('video').innerHTML = '';
	    so.write("video");
		
		if(typeof(caption) != 'undefined'){
			$('mediaDesc').innerHTML = caption;
		}
		
		urchinTracker(trackUrl);
	
		return false;
	}
	
	function writeMediumMediaPlayer(player, xml_file, trackUrl, caption){
		
		var so = new SWFObject(player, "slideshowpro", "592", "482", 9, "#ffffff");    
		so.useExpressInstall(domain + "/expressinstall.swf");
	    so.addParam("allowFullScreen","true"); 
	    so.addVariable("initialURL", escape(document.location));
	    so.addVariable("xmlFile", xml_file);
	    so.addParam("wmode", "transparent");
		$('video').innerHTML = '';
	    so.write("video");
	
		if(typeof(caption) != 'undefined'){
			$('mediaDesc').innerHTML = caption;
		}
		
		urchinTracker(trackUrl);
	
		return false;
	
	}
	
	function writeBigMediaPlayer(player, xml_file, trackUrl, caption, index, div_to_populate){
		
		var so = new SWFObject(player, "slideshowpro", "777", "560", 9, "#ffffff");    
		so.useExpressInstall(domain + "/expressinstall.swf");
	    so.addParam("allowFullScreen","true"); 
	    so.addVariable("initialURL", escape(document.location));
	    so.addVariable("xmlFile", xml_file);
	    so.addParam("wmode", "transparent");
	    
	    if (typeof(div_to_populate) == 'undefined') {
	    	div_to_populate = 'event_images';
	    }
	    
		$(div_to_populate).innerHTML = '';
	    so.write(div_to_populate);
	
		if(caption != null && typeof(caption) != 'undefined'){
			$('mediaDesc').innerHTML = caption;
		}
		
		if(index != null && typeof(index) != 'undefined'){
			video_index_found = index;
			show_video_next_prev();
		}
		
		urchinTracker(trackUrl);
	
		return false;
	
	}
	*/
	
	function writeYouTubePlayer(src, width, height, trackUrl, caption, index, div_to_populate){
		
		embed_code = '<object width="'+width+'" height="'+height+'">' + 
			'<param name="movie" value="'+src+'"></param>' +
			'<param name="allowFullScreen" value="true"></param> ' +
			'<param name="wmode" value="transparent"/> ' +
            '<embed src="'+src+'" type="application/x-shockwave-flash" wmode="transparent" allowfullscreen="true" width="'+width+'" height="'+height+'"></embed>' +
		'</object>';

		if (typeof(div_to_populate) == 'undefined') {
	    	div_to_populate = 'event_images';
	    }

		if(caption != null && typeof(caption) != 'undefined'){
			$('mediaDesc').innerHTML = caption;
		}
		
		if(index != null && typeof(index) != 'undefined'){
			video_index_found = index;
			show_video_next_prev();
		}
		
		urchinTracker(trackUrl);
		
		$(div_to_populate).innerHTML = embed_code;
		return false;
	}


	/*
		This function is used to build the list of shown images in left pane of event/people main landing page.
	*/
	var slideshow_list = null;
	var main_image_list = "mediaTab2_scroll";
	var arr_format = "img";
	
	/*vars for video slideshow*/
	var video_slideshow_list = null;
	var main_video_list = "slideShow_scroll";
	var video_index_found = 0;
	
	/*
		sets image list of event/person, (format=img_elements for slide show) and (format=json list for image detail page bigger image)
	*/
	function set_img_list(img_list, format)
	{
		slideshow_list = img_list;
		arr_format = format;
	}
	
	/*
		set all images under div_name to slideshow_list
	*/
	function slideshow_event_people_landing(div_name)
	{
		/*default div used at event landing is mediaTab2_scroll*/
		if(typeof(div_name)!='undefined') {
			main_image_list = div_name;
		}
		
		//get the img elements from left panel div.
		var media_tab2 =  $(main_image_list);
		if(media_tab2 != null) {
			 set_img_list(media_tab2.select('Img'), "img");
		}
	}
		
	/* initialize list if list not found */
	function initialize_element_list()
	{
		if(slideshow_list == null)
		{
			slideshow_event_people_landing();
		}
	}
	
	
	/*
		set all videos under div_name to video_slideshow_list
	*/
	function video_slideshow_event_people_landing(div_name)
	{
		/*default div is slideShow_scroll*/
		if(typeof(div_name)!='undefined') {
			main_video_list = div_name;
		}
		
		//get the img elements from left panel div.
		var media_tab1 =  $(main_video_list);
		if(media_tab1 != null) {
			 video_slideshow_list = media_tab1.getElementsByClassName('thumbBG');			 
		}
	}
		
	/*
		this function is used get code for onclick handler
	*/
	/*function ret_onclickhandler(big_img_src,title)
	{
		var str = "$('event_bigger_image').src='" + big_img_src + "';$('event_bigger_image').title='" + title + "';RedBox.showInline('div_big_image');show_next_prev();"	
		return str;
	}*/
	
	
	/* 
		this function is used to show images in media-player tab/centered window of the event page		
	*/
	function writeImage(src, title, big_img_src, trackUrl, caption)
	{		
		title = escape(title);		
		urchinTracker(trackUrl);
		
		if(typeof(big_img_src) != 'undefined')
		{
			
			initialize_element_list();
			
			var str = "$('event_bigger_image').src='" + big_img_src + "';$('event_bigger_image').title='" + title + "';RedBox.showInline('div_big_image');show_next_prev();";
			//str = "$('event_bigger_image').src='" + big_img_src + "';$('event_bigger_image').title='" + title + "';RedBox.showInline('div_big_image');"
			title = unescape(title);
			$('event_images').innerHTML = "<img id=\"event_bigger_image\" src=\"" + src + "\" title=\"" + title + "\" onclick=\"" + str + "\" />";			
		}
		else
		{
			$('event_images').innerHTML = "<img id=\"event_bigger_image\" src=\"" + src + "\" title=\"" + title + "\" />";
		}
		
		if(typeof(caption) != 'undefined'){
			$('mediaDesc').innerHTML = caption;
		}
		return false;	
	}
	
	var image_details = function(){
		var title='';
		var url='';
		var summary='';
	}
	
	/*
		This function returns image details from img element or json array list
	*/
	function get_image_by_index(index_id)
	{
		var new_img = new image_details();
	
		if(arr_format == 'img')
		{
			new_img.url = slideshow_list[index_id].src;
			new_img.title = slideshow_list[index_id].title;
			new_img.summary = '';
		}
		else if(arr_format == "array")
		{
			var slideshow_img_obj = slideshow_list[index_id].image;
			if ( typeof(slideshow_img_obj) == "undefined" ) {
				slideshow_img_obj = slideshow_list[index_id];
			}
      new_img.url = slideshow_img_obj.src;
      new_img.title = slideshow_img_obj.title;
      new_img.summary = slideshow_img_obj.summary;
		}
		return new_img;
	}
		
	/*
		This function is used to find the shown image in 'mediaplayer' tab
		and it will find image id from slideshow_list.
	*/
	var index_found = 0;
	function find_image_index(img_src)
	{
		var i = 0;
		//index_found = -1;
		if(slideshow_list != null)
		{
			for(i=0; i<slideshow_list.length; i++)
			{
				if(get_image_by_index(i).url.include(img_src))
				{
					index_found = i;
					break;
				}
			}
		}
		return index_found;
	}
		
	/*
		This function is used to show 'Next' & 'Prev' buttons on the base of the shown image in mediaplayer tab.
	*/	
	function show_next_prev()
	{
		var my_str_arr = $('event_bigger_image').src.split("/");
		var img_position =  find_image_index(my_str_arr[my_str_arr.length-1]);        
		initialize_element_list();

        /*highlight left side thumbs in case of thumbs list available*/
        if($('slideShow_scroll')) {
            for(var i=0; i<slideshow_list.length; i++){
                if(i==img_position){
                    /*highlight style*/
                    $('thumb_img_'+i).setStyle({padding: '2px',left: '0',top: '0',background: '#336699'});
                    
                    /*setting scroll bar and thumbs position*/
                    current_thumb_pos = parseInt($('slideShow_scroll_thumbs').getStyle('top'));
                    proposed_thumb_pos = (img_position-4)*-105;                 //for moving forward (next)
                    proposed_thumb_pos2 = (img_position)*-105;                  //for moving backward (prev)
                    if(current_thumb_pos>proposed_thumb_pos){
                        button_pos = i-5;
                        thumb_pos = i-4;
                        $('slideShow_scroll_thumbs').setStyle({top: ''+(thumb_pos*-105)+'px'});
                        $('slideShow_scroll_button').setStyle({top: ''+((button_pos*20)-1)+'px'});
                    } else if((slideshow_list.length-img_position > 5) && (current_thumb_pos<proposed_thumb_pos2)){
                        $('slideShow_scroll_thumbs').setStyle({top: ''+(i*-105)+'px'});
                        $('slideShow_scroll_button').setStyle({top: ''+((i*20)-1)+'px'});
                    }
                } else {
                    /*clear highlight style*/
                    $('thumb_img_'+i).setStyle({padding: '1px',left: '1px',top: '1px',background: '#999999'});
                }
            }
        }
		
		//hide next prev links for only 1 image
		if(slideshow_list.length==1) {
			$('next_button_slideshow').hide();
			$('prev_button_slideshow').hide();
		} else {
			$('imgCount').update('Photo ' + (img_position+1) + ' of ' + slideshow_list.length)
		}		
	}
	
	/*
		This function is used to show 'Next' & 'Prev' buttons on the base of the shown image in mediaplayer tab.
	*/	
	function show_video_next_prev()
	{

        /*highlight left side thumbs in case of thumbs list available*/
        if($('slideShow_scroll')) {
            for(var i=0; i<video_slideshow_list.length; i++){
                if(i==video_index_found){
                    //highlight style
                    $('thumb_img_'+i).setStyle({padding: '2px',left: '0',top: '0',background: '#336699'});
                } else {
                    //highlight clear
                    $('thumb_img_'+i).setStyle({padding: '1px',left: '1px',top: '1px',background: '#999999'});
                }
            }
        }

		//hide next prev links for only 1 video
		if(video_slideshow_list.length==1) {
			$('next_button_slideshow').hide();
			$('prev_button_slideshow').hide();
		}
		else {
			$('videoCount').update('Video ' + (video_index_found+1) + ' of ' + video_slideshow_list.length)
		}		
	}
	
	/* next navigation */
	function next_image(image_page_url_prefix)
	{
		index_found = index_found + 1;
		if(index_found==slideshow_list.length)
			index_found = 0;
		var img_id = change_big_image(index_found);
		
		urchinTracker(image_page_url_prefix + img_id + '/next');
	}
	
	/* previous navigation */
	function prev_image(image_page_url_prefix)
	{
		index_found = index_found - 1;
		if(index_found==-1)
			index_found = slideshow_list.length-1;
		var img_id = change_big_image(index_found);
		
		urchinTracker(image_page_url_prefix + img_id + '/prev');
	}
	
	/* next navigation */
	function next_video(video_page_url_prefix)
	{
		video_index_found = video_index_found + 1;
		if(video_index_found==video_slideshow_list.length)
			video_index_found = 0;
		video_slideshow_list[video_index_found].onclick();
		show_video_next_prev();
	}
	
	/* previous navigation */
	function prev_video(video_page_url_prefix)
	{
		video_index_found = video_index_found - 1;
		if(video_index_found==-1)
			video_index_found = video_slideshow_list.length-1;
		video_slideshow_list[video_index_found].onclick();
		show_video_next_prev();
	}
	
	/*This function changes bigger image displaying in redbox*/
	function change_big_image(change_image_index)
	{
		if(slideshow_list != null)
		{
			var my_destination_arr = $('event_bigger_image').src.split('/');
			var img_detail = get_image_by_index(change_image_index);
			var src_arr = img_detail.url.split('/');			
			var new_image_url = '';	
			var img_id = '';
			var i = 0;
			
			//getting title of new image
			var new_image_title = img_detail.title;
			
			if(my_destination_arr != null && src_arr != null)
			{
				my_destination_arr[my_destination_arr.length-1] =  src_arr[src_arr.length-1];
				img_id = src_arr[src_arr.length-1].split('.')[0].split('-')[0];				
			}
			
			var dest_length = my_destination_arr.length;			
			for(i=0; i<dest_length; i++)
			{
				if(i == dest_length-1)
				{
					new_image_url += my_destination_arr[i];
				}
				else
				{
					new_image_url += my_destination_arr[i] + "/";
				}
			}
			
			//updating image source
			$('event_bigger_image').src = "";			
			$('event_bigger_image').src = new_image_url;
			
			//updating image title
			$('event_bigger_image').title = "";
			$('event_bigger_image').title = new_image_title;
			
			/*
				right now as we are not able to show descript of image on next & previouse due to shortage of time then at least we should clear description
			*/
			var description_elem = $('mediaDesc');
			if(description_elem != null)			
			{
				if(arr_format != "array") {
					var summary = $('image_summary_'+change_image_index).value;
					description_elem.update(summary);
				} else {
					var summary = img_detail.summary;
					description_elem.update(summary);
				}
			}
			
			show_next_prev();
			
			//return image_id for urchinTacker url
			return img_id;
		}
	}
	
// Need to make the sort slider and the vert scroller use these tools as a general kit 
var SpareTools = {

    // get the absolute x and y coords of the mouse pointer from the top of the page
    getPosition : function(e) {

        e = e || window.event;
        var cursor = {x:0, y:0};

        if (e.pageX || e.pageY) {
            cursor.x = e.pageX;
            cursor.y = e.pageY;
        } else {
                var de = document.documentElement;
                var b = document.body;
            cursor.x = e.clientX +
                (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
            cursor.y = e.clientY +
            (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
            }

        return cursor;
    },

    // move an object to the specified top and left position
    moveObject : function(obj, top, left, bottom, right) {

        // here we have to do some weird stuff because of browser issues
        var units = (navigator.appName == "Microsoft Internet Explorer") ? "" : "px";

        if(top == 0 || (top != undefined && top != "")) {
            obj.style.top = top + units;
        }

        if(right == 0 || (right != undefined && right != "")) {
            obj.style.right = right + units;
        }

        if(bottom == 0 || (bottom != undefined && bottom != "")) {
            obj.style.bottom = bottom + units;
        }

        if(left == 0 || (left != undefined && left != "")) {
            obj.style.left = left + units;
        }        

    },

    // move an object to the specified top and left position
    resizeObject : function(obj, width, height) {
        // here we have to do some weird stuff because of browser issues
        var units = (navigator.appName == "Microsoft Internet Explorer") ? "" : "px";
        if(width != undefined && width != "") {
            obj.style.width = width + units;
        }
        if(height != undefined && height != "" && ! isNaN(height)) {
            obj.style.height = height + units;
        }
    },

    // get the distance an object is from the very top of the screen
    getStartY : function(obj) {
        if(obj.parentNode)
            return obj.offsetTop + this.getStartY(obj.parentNode);
        else
            return 0;
    },
    
    // get the distance an object is from the very left of the screen
    getStartX : function(obj) {
        if(obj.parentNode)
            return obj.offsetLeft + this.getStartX(obj.parentNode);
        else
            return 0;
    },

    // get the distance an object is from wrapper top corner
    getOffsetFromWrapper : function(obj) {
        var coords = {x:0, y:0};

        //alert(obj.id + " " + obj.className + " " + obj.offsetTop);

        if(obj.parentNode && obj.id != "wrapper") {
            var next_coords = this.getOffsetFromWrapper(obj.parentNode);
            coords['x'] = obj.offsetLeft + next_coords['x'];
            coords['y'] = obj.offsetTop + next_coords['y'];
        }

        return coords;
    },

    // get the distance an object is from wrapper top corner
    getOffsetFromRedbox : function(obj) {
        var coords = {x:0, y:0};
        //alert(obj.id + " " + obj.id + " " + obj.offsetLeft);
        if(obj.parentNode && obj.id != "RB_window") {
            var next_coords = this.getOffsetFromRedbox(obj.parentNode);
            coords['x'] = obj.offsetLeft + next_coords['x'];
            coords['y'] = obj.offsetTop + next_coords['y'];
        }

        return coords;
    }

}

var VertScrollFunctions = {
    mouseDown : "",         // contains the value of the current selected slider, since all sliders share these functions
    buttonOffset : 0,

    moveScroll : function(button, buttonPos) {
        var max = button.parentNode.offsetHeight - button.offsetHeight - 1;

        if(buttonPos < -1) {
            buttonPos = -1;
        } else if(buttonPos > max) {
            buttonPos = max;
        }

        var thumbs = document.getElementById(button.parentNode.parentNode.id + "_thumbs");
        var percent = Math.round(buttonPos * 100 / max);
        var thumbsPos = 0;
        if(percent > 0) {
            thumbsPos = -Math.round((thumbs.offsetHeight - thumbs.parentNode.offsetHeight) * percent / 100);
        }

        SpareTools.moveObject(button, buttonPos, "");
        SpareTools.moveObject(thumbs, thumbsPos, "");
    }

}

function VertScroll(id, itemsPerPage, totalItems, selectedItem, moveScrollBox) {
    this.id = id;

    var button = "";
    var thumbs = "";
    var scrollBox = "";
    var scrollUp = "";
    var scrollDown = "";
    // first we need to detect the parts of the scroll set and give them the proper ID's
    // this keeps us from having to assign Id's in the HTML
    var divs = document.getElementById(id).getElementsByTagName("DIV");
    for(var i = 0; i < divs.length; i++) {
        if(divs[i].className == "scroll") {
            scrollBox = divs[i];
            scrollBox.id = id + "_scrollbox";
        }
        if(divs[i].className == "scrollButton") {
            button = divs[i];
            button.id = id + "_button";
        }
        if(divs[i].className == "thumbs") {
            thumbs = divs[i];
            thumbs.id = id + "_thumbs";            
        }
        if(divs[i].className == "scrollUp") {
            scrollUp = divs[i];
            scrollUp.id = id + "_up";
        }
        if(divs[i].className == "scrollDown") {
            scrollDown = divs[i];
            scrollDown.id = id + "_down";
        }
    }

    scrollBox.style.display = "";       // make the scrollbar visible
    if(thumbs.offsetHeight < scrollBox.offsetHeight) {
        scrollBox.style.display = "none";       // if there's no need to scroll hide the bar
    } else {
        scrollUp.parentNode.style.display = "";       // show arrows
        // set the height of the scroll button to match the amount of content
        var pages = thumbs.offsetHeight / scrollBox.offsetHeight;
        SpareTools.resizeObject(button, "", Math.floor(scrollBox.offsetHeight / pages));
        if(moveScrollBox == undefined || moveScrollBox) {
            SpareTools.moveObject(thumbs.parentNode, "", 9);   // move over for the scrollbar
        }
    }

    button.onmousedown = function(event) {
        VertScrollFunctions.mouseDown = this.parentNode.parentNode.id;
        var position = SpareTools.getPosition(event);
        VertScrollFunctions.buttonOffset = position['y'] - SpareTools.getStartY(this.parentNode) - this.offsetTop + this.parentNode.offsetTop;
    };

    scrollUp.onmousedown = function(event) {
        var divs = this.parentNode.parentNode.getElementsByTagName("DIV");
        var button = "";
        for(var i = 0; i < divs.length; i++) {
            if(divs[i].className == "scrollButton") {
                button = divs[i];
                break;
            }
        }

        var buttonPos = button.offsetTop - 20;

        VertScrollFunctions.moveScroll(button, buttonPos);
    };

    scrollDown.onmousedown = function(event) {
        var divs = this.parentNode.parentNode.getElementsByTagName("DIV");
        var button = "";
        for(var i = 0; i < divs.length; i++) {
            if(divs[i].className == "scrollButton") {
                button = divs[i];
                break;
            }
        }

        var buttonPos = button.offsetTop + 20;

        VertScrollFunctions.moveScroll(button, buttonPos);
    };
    
    scrollBox.onclick = function(event) {
        var position = SpareTools.getPosition(event);
        var button = this.getElementsByTagName("DIV")[0];

        if(position['y'] < SpareTools.getStartY(button) || position['y'] > SpareTools.getStartY(button) + button.offsetHeight) {
            var buttonPos = position['y'] - SpareTools.getStartY(this) - button.offsetHeight / 2;
            VertScrollFunctions.moveScroll(button, buttonPos);
        }

    };

    document.onmouseup = function() {
        if(VertScrollFunctions.mouseDown) {
            // allow selecting text
            var element = document.getElementById('wrapper');
            element.onselectstart = function () { } // ie
            element.onmousedown = function () { } // mozilla
            VertScrollFunctions.mouseDown = "";
        }
    };

    document.onmousemove = function(event) {

        if(VertScrollFunctions.mouseDown) {
            // prevent selecting text
            var element = document.getElementById('wrapper');
            element.onselectstart = function () { return false; } // ie
            element.onmousedown = function () { return false; } // mozilla

            var position = SpareTools.getPosition(event);
            var thumbs = document.getElementById(VertScrollFunctions.mouseDown + "_thumbs");
            var button = document.getElementById(VertScrollFunctions.mouseDown + "_button");
            var buttonPos = position['y'] - SpareTools.getStartY(button.parentNode.parentNode) - VertScrollFunctions.buttonOffset;

            var max = button.parentNode.offsetHeight - button.offsetHeight - 1;
            if(buttonPos < -1) {
                buttonPos = -1;
            } else if(buttonPos > max) {
                buttonPos = max;
            }

            var percent = Math.round(buttonPos * 100 / max);
            var thumbsPos = 0;

            if(percent > 0) {
                thumbsPos = -Math.round((thumbs.offsetHeight - thumbs.parentNode.offsetHeight) * percent / 100);
            }

            //document.getElementById('test').innerHTML = percent + "%" + " "  + " = " + thumbsPos + "<sub>px</sub>";

            SpareTools.moveObject(button, buttonPos, "");
            SpareTools.moveObject(thumbs, thumbsPos, "");

        }
    };


}

function Carousel(id, itemsPerPage, totalItems) {


    // object vars
    this.id = id;
    this.totalItems = totalItems;
    this.itemsPerPage = itemsPerPage;
    this.page = document.getElementById(this.id + "Page");
    this.push = document.getElementById(this.id + "Push");
    this.itemIndex = 0;
	page = id + "Page";
	push = id + "Push";

    // loads a set of items into a page object
    this.loadItems = function(direction, page) {
        if(page) {

            page.childNodes[0].innerHTML = "";

            var maxItems = this.itemsPerPage;

            // if we're moving backwards, we actually just move forward all the way back to the spot before
            if(direction == -1) {
                this.itemIndex += this.totalItems - (this.itemsPerPage * 2);
            } else if(direction == 0) {
                maxItems = this.totalItems;
            }

            pageInner = (page.getElementsByClassName('carouselPageInner'))[0];
            // we loop through using modulo so that we can increment evenly and get the wrap arround effect
            for(var i = 0; i < maxItems; i++) {
                var idStr = this.id + "Item" + (this.itemIndex % this.totalItems);
                if(document.getElementById(idStr)) {
                    pageInner.innerHTML += document.getElementById(idStr).innerHTML;
                }
                // mod out value to keep it from getting too large
                this.itemIndex = (this.itemIndex+1) % this.totalItems;
            }

        }
    }

    this.slide = function(direction) {

        this.loadItems(direction, $(push));
        new Effect.Move (this.push,{ x: direction * this.push.offsetWidth, y: 0, duration: 0, mode: 'absolute'});
        new Effect.Move (this.page,{ x: -1 * direction * this.page.offsetWidth, y: 0, duration: 0.5, mode: 'absolute'});
        new Effect.Move (this.push,{ x: 0, y: 0, duration: 0.5, mode: 'absolute'});

        new Effect.Appear(this.push.id, {duration:0.5, from:0.0, to:1.0});
        new Effect.Appear(this.page.id, {duration:0.5, from:1.0, to:0.0});

        // swap the ID's
        var tempId = this.page.id;
        this.page.id = this.push.id;
        this.push.id = tempId;

        // now re-load the objects
        this.page = document.getElementById(this.id + "Page");
        this.push = document.getElementById(this.id + "Push");

    }

    // if there isn't enough items to have to page through
    if(this.totalItems <= this.itemsPerPage) {
        // show only what can be shown, 1 page or less only, no arrows
        document.getElementById(this.id + "Inner").style.width = "100%";
        this.loadItems(0, $(page));
    } else {
        // show the arrows and load starting items
        this.loadItems(1, $(page));		
        document.getElementById(this.id + "Left").style.display = "";
        document.getElementById(this.id + "Right").style.display = "";
    }

    //  move the page and push objects into position
    new Effect.Move (this.page,{ x: 0, y: 0, duration: 0, mode: 'absolute'});
    new Effect.Move (this.push,{ x: this.push.offsetWidth, y: 0, duration: 0, mode: 'absolute'});

//     alert(this.page.style.display);
//     alert(this.push.style.display);
}

// rating functions for the landing page
function rateWait(link, id, mode) {

    if(link.className != "rateWait" && link.className != "rateUpHold" && link.className != "rateDownHold") {

        if (mode == "up") {
            document.getElementById('rateDown' + id).className = "rateDownHold";
        } else {
            document.getElementById('rateUp' + id).className = "rateUpHold";
        }
        link.className = "rateWait";
        link.blur();
        return true;
    }

    link.blur();
    return false;
}

function rateCallback(request, mode, id) {
    if(mode == "up") {
        document.getElementById('rateDown' + id).className = "rateDown";
        document.getElementById('rateUp' + id).className = "rateUpHold";
    } else {
        document.getElementById('rateDown' + id).className = "rateDownHold";
        document.getElementById('rateUp' + id).className = "rateUp";
    }
}

    
function load_slideshow(div, type, contentable_id, content_type){
	
	RedBox.showInline(div);
    var getVars = "";      

	url = "/slideshow/" + type + "/"+contentable_id+"/"+content_type;
	var response_text="";
	
	try{
		new Ajax.Request(url,
					{
				 		parameters:getVars,
				 		asynchronous:true,
				 		onLoading:function(){
				 			Element.show("div_spinner_slideshow");
				 		}.bind(this),
				 		onComplete: function(transport){
				 			new Insertion.Top(div, transport.responseText);
				 			Element.hide("div_spinner_slideshow");
							var vertScrol3 = new VertScroll('slideShow_scroll', 5,0,0);
							if(content_type=='image') {
								slideshow_event_people_landing("slideShow_scroll");
								show_next_prev();
							} else {
								video_slideshow_event_people_landing("slideShow_scroll");
								show_video_next_prev();
								video_index_found = 0;
							}							
				 		}.bind(this) //end Complete function
					}
					);
	} catch(ex){
      log_exceptions("Method: - load slideshow " + ex.message);
	}
	return true;
}

function save_share(shareable_type, shareable_id, share_type) {
	
	try{
		var getVars = "shareable_type=" + shareable_type;
		getVars += "&shareable_id="+shareable_id;
		getVars += "&share_type="+share_type;
		
		new Ajax.Request("/main/save_share",{parameters:getVars,asynchronous:true});
	} catch(ex){
      log_exceptions("Method: - save_share " + ex.message);
	}
}

function toggle_user_score(user_id) {
	try{
		var getVars = "user_id=" + user_id;
		new Ajax.Request("/main/toggle_user_score",
						 {
						 	parameters:getVars,
						 	asynchronous:true,
						 	onComplete: function(transport){
								try {
									if (transport.responseText == "locked") {
										$('toggle_user_score').innerHTML = "Unlock User Score";							
									} else if (transport.responseText == "unlocked") {
										$('toggle_user_score').innerHTML = "Lock User Score";
									}
								}catch(e){
							      log_exceptions("Method: - toggle_user_score " + e.message);
								}
							}.bind(this) //end Complete function
						  }
						 );
		 
	} catch(ex){
      log_exceptions("Method: - toggle_user_score " + ex.message);
	}
}

function toggle_bury_user(user_id) {
	try{
		var getVars = "user_id=" + user_id;
		new Ajax.Request("/user/toggle_user_bury",
						 {
						 	parameters:getVars,
						 	asynchronous:true,
						 	onComplete: function(transport){
								try {
									if (transport.responseText == "bury") {
										$('toggle_bury_user').innerHTML = "<font color='BLACK'>Bury User</font>";
									} else if (transport.responseText == "unbury") {
										$('toggle_bury_user').innerHTML = "<font color='RED'>Un-Bury User</font>";
									}
								}catch(e){
							      log_exceptions("Method: - toggle_user_score " + e.message);
								}
							}.bind(this) //end Complete function
						  }
						 );

	} catch(ex){
      log_exceptions("Method: - toggle_user_score " + ex.message);
	}
}

function toggle_event_display(event_id, type) {
	try{
		var getVars = "id=" + event_id + "&type=" + type;
		new Ajax.Request("/event/update_display_setting",{parameters:getVars,asynchronous:false});	
		location.reload(true);
		} catch(ex){
	      log_exceptions("Method: - toggle_event_display " + ex.message);
		}
}

function report_as_spam(event_id, type) {
	try{
		var getVars = "event_id=" + event_id + "&type=" + type;
		new Ajax.Request("/event/handle_spam",
						 {
						 	parameters:getVars,
						 	asynchronous:true,
						 	onComplete: function(transport){
								try {
									if(type == "fp"){
										$('spam_detection').innerHTML = "(REPORTED AS NOT SPAM)";
									} else if (type =="fn"){
										$('spam_detection').innerHTML = "(REPORTED AS SPAM)";
									}
								}catch(e){
							      log_exceptions("Method: - toggle_user_score " + e.message);
								}
							}.bind(this) //end Complete function
						  }
						 );

	} catch(ex){
      log_exceptions("Method: - toggle_user_score " + ex.message);
	}
}

function delete_copyright_violation(event_id) {
	try{
		var getVars = "event_id=" + event_id
		new Ajax.Request("/event/delete_copyright_violation",
						 {
						 	parameters:getVars,
						 	asynchronous:true,
						 	onComplete: function(transport){
								try {
									$('copyright_violation').innerHTML = "";	
								}catch(e){
							      log_exceptions("Method: - delete copyright violation " + e.message);
								}
							}.bind(this) //end Complete function
						  }
						 );

	} catch(ex){
      log_exceptions("Method: - delete copyright violation " + ex.message);
	}
}

var ProfileManager = Class.create({
  
  initialize: function(element) {
    this.managingElement = element;
    this.dirty = false;
    this._overrideExistingLinks();
    this._addSectionToForm();
  }, 
  
  changeSection: function(event) {
    Event.stop(event);  // don't continue with the onclick event
    var linkElement = Event.element(event);
    var uri = linkElement.getAttribute('href');
    new Ajax.Updater(this.managingElement.down('.main'), uri, {
      method: 'get', 
      evalScripts: true, 
      onComplete: this._doChangeSection.bindAsEventListener(this,linkElement)
    });
  }, 
  
  
  // private
  
  _overrideExistingLinks: function() {
    this.managingElement.select('.side li a').invoke('observe', 'click', this.changeSection.bindAsEventListener(this));
  }, 
  
  _doChangeSection: function(payload, linkElement) {
    this.managingElement.select('.side li').invoke('removeClassName', 'selected');
    linkElement.up('li').addClassName('selected');
    this._addSectionToForm();
  }, 
  
  _addSectionToForm: function() {
    if (form = this.managingElement.down('form')) {
      var sectionIdent = this.managingElement.down('.side li.selected').readAttribute('id').gsub('sidelink_for_','');
      var hiddenField = new Element('input', { type:'hidden', name:'section', value:sectionIdent });
      form.insert(hiddenField, 'bottom');
    }
  }
  
});

function uploadImage(event) {
  $$('.graphicBtnSmall').first().replace(new Element('img', { src:'/images/ajax/dot-spinner-red.gif' }));
}



/* time_ago_in_words stuff */
jQuery(document).ready(function() {
			 jQuery('span.time').timeago();
});
