//*************************** FUNCTIONS ***************************//

// find the Object
function findObj(n, d) {
	var p,i,x;
	if (!d) d = document;
	if ((p = n.indexOf('?'))>0 && parent.frames.length) {
		d = parent.frames[n.substring(p + 1)].document;
		n = n.substring(0, p);
	}
	if (!(x=d[n]) && d.all) x = d.all[n];
	for (i=0;!x&&i<d.forms.length;i++) x = d.forms[i][n];
	for (i=0;!x&&d.layers&&i<d.layers.length;i++) x = findObj(n, d.layers[i].document);
	if (!x && d.getElementById) x = d.getElementById(n);
	return x;
}

//validate the Poll
function validatePoll() 
{
	var radioChecked = false;
	var obj = findObj('poll');
	for (i = 0; i < obj.length; i++) 
	{
		if (obj[i].checked)
			radioChecked = true;
	}

	if (!radioChecked)
	{
		document.getElementById('pollwarning').style.display = 'block';
		return false;
	}
	else
	{
		document.getElementById('pollwarning').style.display = 'none';
		return true;
	}
}
	
//Home Updates Block - Hovers/Hides
jQuery(function(){
	jQuery(".chunk_body").mouseenter(function() {
		jQuery(this).find('p.upd_pic').css({'display' : 'none'});
		jQuery(this).find('p.upd_cat span.upd_catname').css({'display' : 'none'});
		jQuery(this).find('p.upd_cat span.upd_meta').css({'display' : 'block'});
		jQuery(this).find('h2 a').css({'color' : '#fff'});
		jQuery(this).find('p').css({'color' : '#999'});
		jQuery(this).find('p a').css({'color' : '#fff'});
    });
	jQuery(".chunk_body").mouseleave(function() {
		jQuery(this).find('p.upd_pic').css({'display' : 'block'});
		jQuery(this).find('p.upd_cat span.upd_catname').css({'display' : 'block'});
		jQuery(this).find('p.upd_cat span.upd_meta').css({'display' : 'none'});
		jQuery(this).find('h2 a').css({'color' : '#292929'});
		jQuery(this).find('p a').css({'color' : '#666'});
    });
});

//Galleries - Hovers/Hides
jQuery(function(){
	jQuery(".block").mouseenter(function() {
		jQuery(this).find('p.block_name a.block_name_name').css({'display' : 'block'});
		jQuery(this).find('p.block_name a.block_name_amount').css({'display' : 'inline'});
		jQuery(this).find('p.block_meta span.block_meta_date').css({'display' : 'block'});
		jQuery(this).find('p.block_meta span.block_meta_likes').css({'display' : 'inline'});
		jQuery(this).find('p.block_meta a.block_meta_comments').css({'display' : 'inline'});
    });
	jQuery(".block").mouseleave(function() {
		jQuery(this).find('p.block_name a.block_name_name').css({'display' : 'inline'});
		jQuery(this).find('p.block_name a.block_name_amount').css({'display' : 'none'});
		jQuery(this).find('p.block_meta span.block_meta_date').css({'display' : 'inline'});
		jQuery(this).find('p.block_meta span.block_meta_likes').css({'display' : 'none'});
		jQuery(this).find('p.block_meta a.block_meta_comments').css({'display' : 'none'});
    });
});

jQuery(function(){
	jQuery(".more .block ").mouseenter(function() {
		jQuery(this).find('p.block_name a.block_name_name').css({'display' : 'block'});
		jQuery(this).find('p.block_name a').css({'color' : '#fff'});
		jQuery(this).find('p.block_name a.block_name_amount').css({'display' : 'inline'});
		jQuery(this).find('p.block_meta span.block_meta_date').css({'display' : 'block'});
		jQuery(this).find('p.block_meta span.block_meta_likes').css({'display' : 'block'});
		jQuery(this).find('p.block_meta a.block_meta_comments').css({'display' : 'block'});
    });
	jQuery(".more .block ").mouseleave(function() {
		jQuery(this).find('p.block_name a.block_name_name').css({'display' : 'block'});
		jQuery(this).find('p.block_name a').css({'color' : '#ff0000'});
		jQuery(this).find('p.block_name a.block_name_amount').css({'display' : 'none'});
		jQuery(this).find('p.block_meta span.block_meta_date').css({'display' : 'inline'});
		jQuery(this).find('p.block_meta span.block_meta_likes').css({'display' : 'block'});
		jQuery(this).find('p.block_meta a.block_meta_comments').css({'display' : 'block'});
    });
});

jQuery(function(){
	jQuery(".mediamashup .block ").mouseenter(function() {
		jQuery(this).find('p.block_name a.block_name_name').css({'display' : 'block'});
		jQuery(this).find('p.block_name a').css({'color' : '#fff'});
		jQuery(this).find('p.block_name a.block_name_amount').css({'display' : 'inline'});
		jQuery(this).find('p.block_meta span.block_meta_date').css({'display' : 'block'});
		jQuery(this).find('p.block_meta span.block_meta_likes').css({'display' : 'block'});
		jQuery(this).find('p.block_meta a.block_meta_comments').css({'display' : 'block'});
    });
	jQuery(".mediamashup .block ").mouseleave(function() {
		jQuery(this).find('p.block_name a.block_name_name').css({'display' : 'block'});
		jQuery(this).find('p.block_name a').css({'color' : '#ff0000'});
		jQuery(this).find('p.block_name a.block_name_amount').css({'display' : 'none'});
		jQuery(this).find('p.block_meta span.block_meta_date').css({'display' : 'inline'});
		jQuery(this).find('p.block_meta span.block_meta_likes').css({'display' : 'block'});
		jQuery(this).find('p.block_meta a.block_meta_comments').css({'display' : 'block'});
    });
});

jQuery(function(){
	jQuery(".mediamashupFlash .block ").mouseenter(function() {
		jQuery(this).find('p.block_name a.block_name_name').css({'display' : 'block'});
		jQuery(this).find('p.block_name a').css({'color' : '#fff'});
		jQuery(this).find('p.block_name a.block_name_amount').css({'display' : 'inline'});
		jQuery(this).find('p.block_meta span.block_meta_date').css({'display' : 'block'});
		jQuery(this).find('p.block_meta span.block_meta_likes').css({'display' : 'block'});
		jQuery(this).find('p.block_meta a.block_meta_comments').css({'display' : 'block'});
    });
	jQuery(".mediamashupFlash .block ").mouseleave(function() {
		jQuery(this).find('p.block_name a.block_name_name').css({'display' : 'block'});
		jQuery(this).find('p.block_name a').css({'color' : '#ff0000'});
		jQuery(this).find('p.block_name a.block_name_amount').css({'display' : 'none'});
		jQuery(this).find('p.block_meta span.block_meta_date').css({'display' : 'inline'});
		jQuery(this).find('p.block_meta span.block_meta_likes').css({'display' : 'block'});
		jQuery(this).find('p.block_meta a.block_meta_comments').css({'display' : 'block'});
    });
});

//Share Pop - Hovers/Hides
jQuery(function(){
	jQuery(".share_contain").mouseenter(function() {
		jQuery(document).find('.share').css({'display' : 'block'});
    });
	jQuery(".share_contain").mouseleave(function() {
		jQuery(document).find('.share').css({'display' : 'none'});
    });
	jQuery("#share_link").click(function() {
		this.select();
    });
});

//Comments - Hovers/Hides
jQuery(function(){
	jQuery(".comment").mouseenter(function() {
		jQuery(this).find('span.com_meta_time').css({'display' : 'none'});
		jQuery(this).find('span.com_meta_abuse').css({'display' : 'inline'});
		jQuery(this).find('span.com_meta_name').css({'color' : '#fff'});

    });
	jQuery(".comment").mouseleave(function() {
		jQuery(this).find('span.com_meta_abuse').css({'display' : 'none'});
		jQuery(this).find('span.com_meta_time').css({'display' : 'inline'});
		jQuery(this).find('span.com_meta_name').css({'color' : '#ff0000'});
		jQuery(this).find('span.com_meta_blurb').css({'color' : '#fff'});
    });
});

jQuery(function(){
	jQuery(".comment").mouseenter(function() {
		jQuery(this).find('span.com_meta_abuse a').css({'color' : '#ff9192'});
		jQuery(this).find('p.com_blurb').css({'color' : '#fff'});
    });
	jQuery(".comment").mouseleave(function() {
		jQuery(this).find('span.com_meta_abuse a').css({'color' : '#939598'});
		jQuery(this).find('p.com_blurb').css({'color' : '#fff'});
    });
});

//Comments - Hovers/Hides
jQuery(function(){
	jQuery(".update").mouseenter(function() {
		jQuery(this).find('span.update_text').css({'display' : 'none'});
		jQuery(this).find('span.update_meta').css({'display' : 'none'});
		jQuery(this).find('span.update_btns').css({'display' : 'inline'});
		jQuery(this).find('a').css({'color' : '#fff'});
    });
	jQuery(".update").mouseleave(function() {
		jQuery(this).find('span.update_text').css({'display' : 'inline'});
		jQuery(this).find('span.update_meta').css({'display' : 'inline'});
		jQuery(this).find('span.update_btns').css({'display' : 'none'});
		jQuery(this).find('a').css({'color' : '#3c3c3c'});
    });
});

//poll Toggle
jQuery(function(){
	jQuery(".polllink").click(function() {
		jQuery(".poll").find('p.poll_answ').css({visibility: "visible", display: "none"}).hide();
		jQuery(".poll").find('p.poll_btn').css({visibility: "visible", display: "none"}).hide();
		jQuery(".poll").find('p.poll_res').css({visibility: "visible", display: "none"}).show();
	});
});

//form Bg Position Shifting
jQuery(function() {
	jQuery(".shift").click(function () {
      jQuery(this).css({'background-position' : '0px -31px'});
    });
	jQuery(".shift input").blur(function () {
      jQuery(".shift").css({'background-position' : '0px 0px'});
    });
	jQuery(".shift_plenty").click(function () {
      jQuery(this).css({'background-position' : '0px -117px'});
    });
	jQuery(".shift_plenty textarea").blur(function () {
      jQuery(".shift_plenty").css({'background-position' : '0px 0px'});
    });
});

//search Bg Position Shifting
jQuery(function() {
	jQuery(".search p.field input").click(function () {
      jQuery(".search p.field").css({'background-position' : '0px -27px'});
    });
	jQuery(".search p.field input").blur(function () {
      jQuery(".search p.field").css({'background-position' : '0px 0px'});
    });
});

//global Updates Tabs + social Tabs
jQuery(function() {
	jQuery(".global_updates, .social_body").hide(); //Hide all content
	jQuery("ul.global_updates_nav a:first, ul.social_nav a:first").addClass("selected").show(); //Activate first tab
	jQuery(".global_updates:first, .social_body:first").show(); //Show first tab content
	
	jQuery("ul.global_updates_nav a, ul.social_nav a, a.user_reply").click(function() {
		jQuery("ul.global_updates_nav a, ul.social_nav a, a.user_reply").removeClass("selected"); //Remove any "active" class
		jQuery(this).addClass("selected"); //Add "active" class to selected tab
		jQuery(".global_updates, .social_body").hide(); //Hide all tab content
		var activeTab = jQuery(this).attr("rel"); //Find the rel attribute value to identify the active tab + content
		jQuery(activeTab).fadeIn(); //Fade in the active content
		jQuery(".form_mode").val($(this).attr("rel").replace("#gallery_", ""))
		return false;
	});
	
	jQuery("a.user_reply").click(function() {
		jQuery("ul.social_nav a").removeClass("selected");
		jQuery("ul.social_nav a:last").addClass("selected");
	});
	
});

//global Updates tabs
jQuery(function() {
	jQuery('ul.global_updates_nav li.dj_updates a.selected, ul.global_updates_nav li.friend_updates a.selected').parent().css({"background":"#fff"});
	jQuery("ul.global_updates_nav a").click(function () {
		if (jQuery("ul.global_updates_nav li.dj_updates a").hasClass("selected")) {
			jQuery("ul.global_updates_nav li.dj_updates").css({"background":"#fff"});
			jQuery("ul.global_updates_nav li.friend_updates").css({"background":"#3c3c3c"});
		} else 
		if (jQuery("ul.global_updates_nav li.friend_updates a").hasClass("selected")) {
			jQuery("ul.global_updates_nav li.friend_updates").css({"background":"#fff"});
			jQuery("ul.global_updates_nav li.dj_updates").css({"background":"#3c3c3c"});
		}
	});
});

//show/hide Facebook Connect
jQuery(function() {
	jQuery('.social_item').hover(
		function () {
			jQuery(this).find('p.user_actions').show();
		}, 
		function () {
			jQuery(this).find('p.user_actions').hide();
		}
	);
});

//show/hide Friends
jQuery(function() {
	jQuery('.friend_item').hover(
		function () {
			jQuery(this).find('p.user_date, p.user_name, p.user_meta').hide();
			jQuery(this).find('p.user_sendmessage, p.user_viewprofile, p.user_unfriend').show();
		}, 
		function () {
			jQuery(this).find('p.user_date, p.user_name, p.user_meta').show();
			jQuery(this).find('p.user_sendmessage, p.user_viewprofile, p.user_unfriend').hide();
		}
	);
});

//show/hide Message
jQuery(function() {
	jQuery(".social_item").find("div.user_message p:first").show();
	jQuery("a.show_some_message").click(function () {
	    jQuery(this).parent().parent().find("div.user_message *:not(:first)").slideToggle();
		jQuery(this).parent().parent().find("div.user_message p").show();
	});
});

//show/hide Status update btn
jQuery(function() {
	jQuery('.logged_status').hover(
		function () {
			jQuery(this).find('p.status_update_btn').show();
		}, 
		function () {
			jQuery(this).find('p.status_update_btn').hide();
		}
	);
});

//************************* SHINY EFFECTS **************************//

jQuery(document).ready(function() {
	jQuery.easing.def = "easeInOutSine"; 
	jQuery('.chunk_body, .post_intro, .box_update_item, .update, .friend_item').bind('mouseenter',function(){
		jQuery(this).stop().animate({
			backgroundColor: "none" }, 200)
			//$(this).fadeTo("fast", 0.5); // This should set the opacity to 100% on hover
	}).bind('mouseleave',function(){
		jQuery(this).stop().animate({
			backgroundColor: "none" }, 300)
		//	$(this).fadeTo("fast", 0.0); // This should set the opacity to 100% on hover
		
	});
});

jQuery(function(){
	jQuery(".page_container.recent .block").mouseenter(function() {
		jQuery(this).find('p.block_meta').css({'color' : '#939598'});
    });
	jQuery(".page_container.recent .block").mouseleave(function() {
		jQuery(this).find('p.block_meta').css({'color' : '#939598'});
    });
});

jQuery(function(){
	jQuery(".page_container.more .block").mouseenter(function() {
      jQuery(this).css({'background' : 'url("/media/desktop/images/bg-focus.png")'});   
    });
	jQuery(".page_container.more .block").mouseleave(function() {
	  jQuery(this).css({'background' : 'url("/media/desktop/images/bg-logged-tile.png")'});
    });
});

jQuery(function(){
	jQuery(".page_container.mediamashup .block").mouseenter(function() {
      jQuery(this).css({'background' : 'url("/media/desktop/images/bg-focus.png")'});   
    });
	jQuery(".page_container.mediamashup .block").mouseleave(function() {
	  jQuery(this).css({'background' : 'url("/media/desktop/images/bg-logged-tile.png")'});
    });
});

jQuery(function(){
	jQuery(".mediamashupFlash .block").mouseenter(function() {
      jQuery(this).css({'background' : 'url("/media/desktop/images/bg-focus.png")'});   
    });
	jQuery(".mediamashupFlash .block").mouseleave(function() {
	  jQuery(this).css({'background' : 'url("/media/desktop/images/bg-logged-tile.png")'});
    });
});

jQuery(function(){
	jQuery(".comment").mouseenter(function() {
      jQuery(this).css({'background' : '#ff0000'});   
    });
	jQuery(".comment").mouseleave(function() {
	  jQuery(this).css({'background' : 'none'});
    });
});

function init_comment_hover(){
	jQuery(".comment").mouseenter(function() {
		jQuery(this).find('span.com_meta_time').css({'display' : 'none'});
		jQuery(this).find('span.com_meta_abuse').css({'display' : 'inline'});
		jQuery(this).find('span.com_meta_name').css({'color' : '#fff'});

    });
	jQuery(".comment").mouseleave(function() {
		jQuery(this).find('span.com_meta_abuse').css({'display' : 'none'});
		jQuery(this).find('span.com_meta_time').css({'display' : 'inline'});
		jQuery(this).find('span.com_meta_name').css({'color' : '#ff0000'});
		jQuery(this).find('span.com_meta_blurb').css({'color' : '#fff'});
    });
    
	jQuery(".comment").mouseenter(function() {
		jQuery(this).find('span.com_meta_abuse a').css({'color' : '#ff9192'});
		jQuery(this).find('p.com_blurb').css({'color' : '#fff'});
    });
	jQuery(".comment").mouseleave(function() {
		jQuery(this).find('span.com_meta_abuse a').css({'color' : '#939598'});
		jQuery(this).find('p.com_blurb').css({'color' : '#fff'});
    });
    
	jQuery(".comment").mouseenter(function() {
      jQuery(this).css({'background' : '#ff0000'});   
    });
	jQuery(".comment").mouseleave(function() {
	  jQuery(this).css({'background' : 'none'});
    });
}



//************************* GALLERY **************************//

jQuery(function() {
jQuery(".thumb_carousel").jCarouselLite({
        btnNext: ".thumbs_next",
        btnPrev: ".thumbs_prev",
    	speed: 500,
		circular: false
    });
});

// Initially set opacity on thumbs and add
// additional styling for hover effect on thumbs
var onMouseOutOpacity = 0.67;
jQuery('#thumbs ul.thumbs li').css('opacity', onMouseOutOpacity)
	.hover(
		function () {
			jQuery(this).not('.selected_thumb').fadeTo('fast', 1.0);
		}, 
		function () {
			jQuery(this).not('.selected_thumb').fadeTo('fast', onMouseOutOpacity);
		}
	);

jQuery(function() {
	// Initialize Advanced Galleriffic Gallery
	var galleryAdv = jQuery('#gallery').galleriffic('#thumbs', {
		delay:                  2000,
		numThumbs:              12,
		preloadAhead:           10,
		enableTopPager:         false,
		enableBottomPager:      false,
		imageContainerSel:      '#slideshow',
		controlsContainerSel:   '#controls',
		captionContainerSel:    '#caption',
		loadingContainerSel:    '#loading',
		renderSSControls:       false,
		renderNavControls:      false,
		playLinkText:           'Play Slideshow',
		pauseLinkText:          'Pause Slideshow',
		prevLinkText:           '&lsaquo; Previous Photo',
		nextLinkText:           'Next Photo &rsaquo;',
		nextPageLinkText:       'Next &rsaquo;',
		prevPageLinkText:       '&lsaquo; Prev',
		enableHistory:          false,
		autoStart:              false,
		onChange:               function(prevIndex, nextIndex) {
			jQuery('#thumbs ul.thumbs').children()
				.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
				.eq(nextIndex).fadeTo('fast', 1.0);
		},
		onTransitionOut:        function(callback) {
			jQuery('#caption').fadeTo('fast', 0.0);
			jQuery('#slideshow').fadeTo('fast', 0.0, callback);
		},
		onTransitionIn:         function() {
			jQuery('#slideshow').fadeTo('fast', 1.0);
			jQuery('#caption').fadeTo('fast', 1.0);
		},
		onPageTransitionOut:    function(callback) {
			jQuery('#thumbs ul.thumbs').fadeTo('fast', 0.0, callback);
		},
		onPageTransitionIn:     function() {
			jQuery('#thumbs ul.thumbs').fadeTo('fast', 1.0);
		}
	});
});

// Logout
$(function() {
    $("#sign_out").live("click", function () {
        var currentTime = new Date();
        var time = currentTime.getTime();
        $("#account_links").load("/logout?" + time);
    });
});


// Like
function afterLike(data)
{
    json = eval(data);
    jQuery(".ps_likes_num").text(json.score.score);
}

$(function() {
    $("#like_link").live("click", function () {
        var data = {};
        jQuery.post(jQuery(this).attr('href'), 
            data, 
            afterLike,
            "json"
        );
        return false;
    });
});

// All forms
function bindForm() {
	$(".shift").click(function () {
	    $(this).css({'background-position' : '0px -31px'});
	});
	$(".shift input").blur(function () {
	    $(".shift").css({'background-position' : '0px 0px'});
	});
    $(".shift input").keydown(function () {
        error_label = $("label[class='error'][for='" + $(this).attr("id") + "']");
        if (error_label.length > 0)
            error_label.remove();
	});
}

// Comments
function validateComments() {
    var validator = $("#frmComments").validate({
        onkeyup: false,
        onclick: false,
        submitHandler: function(form) {
            $("#register_buttons").hide();
            $("#register_progress").show();
            $('#frmComments').ajaxSubmit(function(response){
                $("#comments").replaceWith(response);
	            bindForm();
                validateComments();
                init_comment_hover();
            }); 
        },
        rules: {
            comment: {
                required: true
            }
        }
    });
}

// Paginate Comments
function paginatedComments(c, i, n){
    $.ajax({
		url:'/comment-list/' + c + '/' + i + '/'+ n + '/',
		async: false,
		success: function(response){
            if(response != ''){
                $("#comments").replaceWith(response);
                init_comment_hover();
            }
            else{
                $('#comment_paging').hide();
            }
		}
	});
}

// Login
function validateLogin(){
    var validator = $("#frmLogin").validate({
        onkeyup: false,
        onclick: false,
        submitHandler: function(form) {
            $('#frmLogin').ajaxSubmit(function(response) {
                if(response == 'login_successful'){
                    window.location = '/home/';
                }
                else{
                    $("#frmLoginSpan").replaceWith(response);
                    bindForm();
                    validateLogin();
                }
            });
        }
    });
}
 
// Password reminder
function validatePasswordReminder(){
    var validator = $("#frmPasswordReminder").validate({
        onkeyup: false,
        onclick: false,
        submitHandler: function(form) {
            $('#frmPasswordReminder').ajaxSubmit(function(response) {
                $("#spnPasswordReminder").replaceWith(response);
                bindForm();
                validateLogin();
            });
        }
    });
}

// Email Mashup
function validateEmailMashup(){
    var validator = $("#frmEmailMashup").validate({
        onkeyup: false,
        onclick: false,
        submitHandler: function(form) {
            $('#frmEmailMashup').ajaxSubmit(function(response){
                $("#spnEmailMashup").replaceWith(response);
	            bindForm();
                validateEmailMashup();
            }); 
        }
    });
}

function clearFieldsReportAbuse(){
    $('form').find('input').each(function(){
        show_initial_val($(this))
    });
    $('form').find('input').focus(function(){
        clear_initial_val($(this))
    });
    $('form').find('input').blur(function(){
        show_initial_val($(this))
    });
    $("#frmReportAbuse").submit(function(){
        $('form').find('input').each(function(){
            clear_initial_val($(this))
        });
    });
}

// Report Abuse
function validateReportAbuse(){
    var validator = $("#frmReportAbuse").validate({
        onkeyup: false,
        onclick: false,
        submitHandler: function(form) {
            $('#frmReportAbuse').ajaxSubmit(function(response) {
                $("#spnReportAbuse").replaceWith(response);
                bindForm();
                validateReportAbuse();
                clearFieldsReportAbuse();
            });
        }
    });
}

jQuery(document).ready(function() {
	jQuery.easing.def = "easeInOutSine"; 
	jQuery('.block.test').bind('mouseenter',function(){
		jQuery(this).stop().animate({
			backgroundColor: "#ff0000" }, 200)
			$(this).fadeTo("fast", 0.5); // This should set the opacity to 100% on hover
	}).bind('mouseleave',function(){
		jQuery(this).stop().animate({
			backgroundColor: "#ffffff" }, 200)
			$(this).fadeTo("fast", 1.0); // This should set the opacity to 100% on hover
	});
});

function clear_initial_val(ele){
    if(ele.val() == ele.attr('rel')){
        ele.val('');
    }
}

function show_initial_val(ele){
    if(ele.val() == ''){
        ele.val(ele.attr('rel'));
    }
}

function dblclick_twitter(url){
    var axel = Math.random()+"";
    var a = axel * 10000000000000;
    document.write('<IMG SRC="http://ad.doubleclick.net/activity;src=2648622;type=smirn109;cat=follo089;ord=1;num='+ a + '?" WIDTH=1 HEIGHT=1 BORDER=0>');
    window.location = 'http://twitter.com/' + url;
}

function dblclick_facebook(url){
    var axel = Math.random()+"";
    var a = axel * 10000000000000;
    document.write('<IMG SRC="http://ad.doubleclick.net/activity;src=2648622;type=smirn109;cat=joinf800;ord=1;num='+ a + '?" WIDTH=1 HEIGHT=1 BORDER=0>');
    window.location = 'http://www.facebook.com/' + url; 
}

// Infostrap
jQuery(function(){
	$('.thumb img').click(function(){
        var info_list = new Array();
        var image_info = $(this).attr('rev');
        info_list = image_info.split('§');
        
        $('.infoStrap h1').html(info_list[0]);
        $('.infoStrap p').html(info_list[1]);
    });
});

// Gallery Info Strap
jQuery(function(){
	jQuery("#gallery").mouseenter(function() {
        $('.advance-link').attr('href', '');
        $('.advance-link').css('cursor', 'default');
		jQuery(document).find('.infoStrap').css({'display' : 'block'});
    });
	jQuery("#gallery").mouseleave(function() {
        $('.advance-link').attr('href', 'default');
        $('.advance-link').css('cursor', '');
		jQuery(document).find('.infoStrap').css({'display' : ''});
    });
});

function toggle_results_paging(){
    var counter = $('#result_count').attr('rel');
    
    if($('#poll_results_1').is(":visible")){
        $(".results_previous").hide();
    }
    else{
        $(".results_previous").show();
    }
    if($('#poll_results_' + counter).is(":visible")){
        $(".results_next").hide();
    }
    else{
        $(".results_next").show();
    }
}

// Poll Results Paging
$(function(){
    
    toggle_results_paging();
    
    $(".results_previous").click(function(){
        var current = $(this).attr('href').replace('#', '');
        var previous = parseInt(current) - 1;
        $('#poll_results_' + current).hide();
        $('#poll_results_' + previous).fadeIn();
        toggle_results_paging();
    });
    
    $(".results_next").click(function(){
        var current = $(this).attr('href').replace('#', '');
        var next = parseInt(current) + 1;
        $('#poll_results_' + current).hide();
        $('#poll_results_' + next).fadeIn();
        toggle_results_paging();
    });
});

jQuery(function(){
	if (jQuery(".poll_item").hasClass("selected")) {
        
	}
	else
		jQuery(".poll_item").mouseenter(function() {
			jQuery(this).css({'background' : 'url("/media/desktop/images/bg-focus.png") 0 0 repeat'});
			jQuery(this).find('h4').css({'color' : '#fff'});
		});
		jQuery(".poll_item").mouseleave(function() {
			jQuery(this).css({'background' : 'url("/media/desktop/images/bg-logged-tile.png") 0 0 repeat'});
			jQuery(this).find('h4').css({'color' : '#ff0000'});
		});
});

$(function(){
    $(".poll_item").click(function(){
        if($(document).find('.poll_item').hasClass('selected') == false){
            var option_id = $(this).attr('id');
            $(this).addClass("selected");
            $.ajax({
                url:'/mashup-polls/vote/' + option_id + '/',
                async: false
            });
        }
    });
});

$(function(){
	$("#add_another_image").click(function(){
		var seq = $(this).attr('rel');
		var next_seq = parseInt(seq) + 1;
		if(seq <= 5){
			$('#image_upload_' + seq).fadeIn();
			$(this).attr('rel', next_seq);
		}
		if(seq == 5){
			$(".upLoadMore").hide();
		}
	});
})
