jQuery(document).ready(function () 
{
    /* Build Tweetstream*/
//    var url = "http://api.twitter.com/1/blendtweets/lists/cmsummit-speakers/statuses.json?callback=?";
    if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
        jQuery('#menubar').remove();
        jQuery('#touch').show();
        jQuery('div.gallery-videos').remove();
    } else {
        var url = "http://api.twitter.com/1/cmsummit/lists/speakers2010/statuses.json?callback=?";
        jQuery('#tweets').tweetStream(url, {templateId: 'tweet_tpl'});
    }

    /* Build pop-up for video & images. */
    var dialog=$('<div class="dialog" id="dialog" style="display: none"></div>');

    jQuery('body').append(dialog);

    jQuery('#dialog').dialog({modal: true, title: jQuery(this).attr('title'), width: 680, height: 580, autoOpen:false, resizable: false});

    /* Set equalhieghts for tweet column no matter how long the Content is. */

	if (!$('div.blog-post-full').exists()) {

		jQuery('#Content, #tweet_pane').equalHeights();
		var tpHeight = jQuery('#tweet_pane').height();
		jQuery('#tweet_pane').height(tpHeight - 225);


	}

    jQuery('#Sponsors div.sponsor-block').equalHeights();

    if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {    
        jQuery('div.gallery-photos div.photos').scroller({perPage: 2, itemClass: 'galleryline', leftButton: ' ', rightButton: ' '});
    } else {
        jQuery('.videos').scroller({perPage: 8, itemClass: 'galleryline', leftButton: ' ', rightButton: ' '});
        //jQuery('div.gallery-photos div.photos').scroller({perPage: 8, itemClass: 'galleryline', leftButton: ' ', rightButton: ' '});
    }
    
    jQuery("button.addimg").toggle(function(){
        jQuery(this)[0].innerHTML = "  close ^  ";
        jQuery(this).parent('div').siblings('div.upload').slideDown('fast',
        function(){
            // Recalculate the hieghts.
            var ch = jQuery('#Content').height();
            jQuery('#Content').height(ch + 110);
        });
    }, function(){
        jQuery(this)[0].innerHTML = jQuery(this).val();
        jQuery(this).parent('div').siblings('div.upload').slideUp('fast',
        function(){
            // Recalculate the hieghts.
            var ch = jQuery('#Content').height();
            jQuery('#Content').height(ch - 110);
        });
    });

});


jQuery.fn.exists = function(){return jQuery(this).length>0;}

$(document).ready(function() {
	$('.popUpScroll').live('click', function(e)
	{
		var _id = $(this).attr('id').substring(5);
			
		if (_id!='0')
		{
			jQuery('#dialog').dialog('close');
			var _this = $('#'+_id);

			jQuery('#dialog').html('<a class="popUpScroll popUpScrollLeft" id="prev_'+_this.attr('prev')+'" href="#"></a><a class="popUpScroll popUpScrollRight" id="next_'+_this.attr('next')+'" href="#"></a><img src="'+_this.attr('href')+'"/> <br /> '+_this.attr('title'));
												
			jQuery('#dialog').dialog('open');
		}

		e.preventDefault();
		return false;
	});
    $('.gallery-photos .design').flickrSet(
                                           {photoset_id: '72157624123845749',
                                           api_key: '93bc1b7aa05112fe286503927fc48879',
                                           onComplete: function () {
                                                $('.gallery-photos .photos').scroller({perPage: 8, itemClass: 'galleryline', leftButton: ' ', rightButton: ' '});
                                                jQuery('.image a[rel^=lightbox]').click( function (e) 
                                                {
                                                    //jQuery('#dialog').html('<iframe class="photoframe" width="640" height="500" style="width:640px height: 500px;" id="dialogframe" src="' +
                                            
												    //jQuery(this).attr('href') + '"></iframe>');

													jQuery('#dialog').html('<a class="popUpScroll popUpScrollLeft" id="prev_'+jQuery(this).attr('prev')+'" href="#"></a><a class="popUpScroll popUpScrollRight" id="next_'+jQuery(this).attr('next')+'" href="#"></a><img src="'+jQuery(this).attr('href')+'"/> <br /> '+jQuery(this).attr('title'));
                                            
                                                    jQuery('#dialog').dialog('open');
                                            
                                                    e.preventDefault();
                                            
                                                    return false;
                                                });
												
                                                jQuery('.video a[rel^=lightbox]').click( function (e) 
                                                {
                                                    jQuery('#dialog').html('<iframe class="photoframe" width="640" height="500" style="width:640px height: 500px;" id="dialogframe" src="' +
                                            
												    jQuery(this).attr('href') + '"></iframe>');
                                                    jQuery('#dialog').dialog('open');
                                            
                                                    e.preventDefault();
                                            
                                                    return false;
                                                });

                                                
                                            }});
    
    //$('.gallery-slides .design').slideSet({username: 'CMSummit'});
    //$('#flickr_div').flickrGallery('72157624123845749','93bc1b7aa05112fe286503927fc48879');

});


